Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.albasani.net!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!81.171.88.16.MISMATCH!hq-usenetpeers.eweka.nl!hq-usenetpeers.eweka.nl!bcyclone04.am1.xlned.com!bcyclone04.am1.xlned.com!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.008 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'subject: -- ': 0.07; 'subject:bug': 0.07; 'wednesday,': 0.07; '"if': 0.09; 'imported': 0.09; 'mixed': 0.09; 'namespace': 0.09; 'toplevel': 0.09; 'python': 0.11; 'def': 0.12; "'from": 0.16; 'collections': 0.16; 'subject:?)': 0.16; ':-)': 0.16; 'sender:addr:gmail.com': 0.17; 'wrote:': 0.18; 'module': 0.19; 'import': 0.22; 'hack': 0.22; 'to:name:python-list@python.org': 0.22; 'looks': 0.24; 'header:In- Reply-To:1': 0.27; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; 'not.': 0.33; "i'd": 0.34; 'problem.': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'thanks': 0.36; 'should': 0.36; 'filter': 0.38; 'gmail': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'short': 0.38; 'to:addr:python.org': 0.39; 'skip:u 10': 0.60; 'removing': 0.60; 'name': 0.63; 'skip:n 10': 0.64; 'decided': 0.64; 'sweet': 0.74; 'abc': 0.84; 'terrible': 0.84; 'obvious,': 0.91; 'ware': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:content-type; bh=fyWjf95jD8/JV9D4T+tR8pfVGYHifBEKa0WV/jfz39c=; b=eGhsqtOGhxjFAipzZTJAhC4K5MqmrszbtnskiJ/xJNd0dgznD3U7knfvHcn+fuTWHr 7VaeYWaIfs9oqbBSG96zCrfKF5AJuyyYgRfRXaa+xj6jcWATPcKQfpEuuXSLgI1OJlQt aWPBlpoavnFoMSOC0Ol0nQsBgRhhrXwt7YX4BjcNDlFEpoXJBtujEhIYvg4Ia+AiCiJn xq5FXgYbt0q73vRGtpcOmlrirDPNNNC1+7B7YPEt5xOjrRWrCds2bDfgJQxKtLgheais o3vOv1zpNduUhQI5p4lJ08QMt0WGKULqv5NtMxu6VgteGuKxLz3RzIGecCEk55YHD4W2 1GoA== X-Received: by 10.60.76.198 with SMTP id m6mr6722685oew.12.1414558773501; Tue, 28 Oct 2014 21:59:33 -0700 (PDT) MIME-Version: 1.0 Sender: zachary.ware@gmail.com In-Reply-To: <593c0099-770f-48cd-b7ba-22154b00f130@googlegroups.com> References: <94e3143a-c9ab-433d-8b3d-6ab296de14d9@googlegroups.com> <593c0099-770f-48cd-b7ba-22154b00f130@googlegroups.com> From: Zachary Ware Date: Tue, 28 Oct 2014 23:59:13 -0500 X-Google-Sender-Auth: 6WLRkhNlFuuShFamj2S_vuojevA Subject: Re: What for -- for? (was A bug?) To: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 33 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1414558776 news.xs4all.nl 2925 [2001:888:2000:d::a6]:59575 X-Complaints-To: abuse@xs4all.nl X-Received-Body-CRC: 1644437870 X-Received-Bytes: 5068 Xref: csiph.com comp.lang.python:79880 On Tue, Oct 28, 2014 at 11:40 PM, Rustom Mody wrote: > On Wednesday, October 29, 2014 9:53:46 AM UTC+5:30, Zachary Ware wrote: >> On Tue, Oct 28, 2014 at 11:16 PM, Zachary Ware wrote: >> > def get_abc_map(cls): >> > return {n: issubclass(cls, getattr(abc, n)) for n in dir(abc) if >> > n[0].isupper()} >> >> Of course, Gmail decided to wrap my long line for me. In case it's >> not obvious, that should be a single line. > > Thanks > > Wrapping -- no problem. > But the isupper looks like black-magic :-) > > And removing the ' ... if n[0].isupper()' > breaks the code It's a terrible hack for 2/3 compatibility; in 3 I'd do "if not n.startswith('__')" since the Python 3 collections.abc module only contains ABCs (and the standard dunder names). Python 2 has all the ABCs mixed into the toplevel collections namespace with some other non-ABCs, but it happens that all the ABCs are capitalized, while the non-ABCs are not. The ABCs are imported into collections from _abcoll, but _abcoll also some uncapitalized non-ABCs as well. For somewhat greyer magic, do 'from abc import ABCMeta' and filter the collections<.abc> namespace with isinstance(obj, ABCMeta). I just used the above because it's short and sweet and keeps the name handy :) -- Zach