[Python-Dev] PEP 8 updates/clarifications

Ian Bicking ianb at colorstudy.com
Mon Dec 12 21:25:54 CET 2005


Barry Warsaw wrote:
> On Fri, 2005年12月09日 at 17:19 -0600, Ian Bicking wrote:
>>>>I personally feel "cls" should be used for classmethods, and not 
>>elsewhere. Just like I wouldn't like someone using "self" outside of 
>>the first argument of instance methods. So class_ still would be a good 
>>spelling elsewhere.
>>> Here's what I've written:
>> Function and method arguments
>> Always use 'self' for the first argument to instance methods.
>> Always use 'cls' for the first argument to class methods.
>> If a function argument's name clashes with a reserved keyword, it is
> generally better to append a single trailing underscore rather than use
> an abbreviation or spelling corruption. Thus "print_" is better than
> "prnt".

That looks good to me. Well, I actually try not to use cls as the first 
argument to metaclass's __new__ method, because there's so many classes 
being tossed about at that point that I try to be more explicit. But I 
don't consider that a common enough issue to be worth mentioning in PEP 8.
>>I looked at that too, but most of these didn't jump out at me. I'll 
>>copy in the parts that aren't already in PEP 8 that seem possible:
>>>> From-imports should follow non-from imports. Dotted imports should 
>>follow
>> non-dotted imports. Non-dotted imports should be grouped by increasing
>> length, while dotted imports should be grouped roughly alphabetically.
>>>>This seems too complex to me for PEP 8.
>>> Really? ISTR adopting this convention from Guido, but I'm not 100% sure
> about that. After having used it for several years now, I do really
> like this style, but I'm willing to leave the recommendation out of PEP
> 8.

It seems so exacting to me; stdlib, external modules, internal modules 
seems like enough ordering to me. If you want to order things more 
exactly, sure, but I don't really see the point personally. Since I 
can't assume as a reader that imports are ordered in any way I have to 
search to be sure of what's there. The grouping help me browse, but I'd 
hope that the import list is short enough that I don't need to use 
alphabetization to scan for a module.
-- 
Ian Bicking / ianb at colorstudy.com / http://blog.ianbicking.org


More information about the Python-Dev mailing list

AltStyle によって変換されたページ (->オリジナル) /