LWN.net Logo

What's new in Python 2.6

What's new in Python 2.6

Posted Sep 2, 2008 11:46 UTC (Tue) by MiguelAtWork (guest, #53380)
Parent article: What's new in Python 2.6

I love Python, but I really wish they would fix a couple of annoyances:

  • Naming conventions. Right now, they seem to sort-of-randomly use: lowercasewithoutunderscores, lowercase_with_underscores, MixedCase and even UPPERCASE_WITH_UNDERSCORES.
  • Potential name clashes with user code. They periodically introduce new built-in functions and modules with common names (e.g. apparently next() in 2.6), which can potentially be a problem when updating old code that might redefine them to something else.


(Log in to post comments)

What's new in Python 2.6

Posted Sep 2, 2008 13:14 UTC (Tue) by jamesh (guest, #1159) [Link]

Most new modules follow the PEP 8 naming guidelines, and some of the Python 3.0 compatibility breaks are to fix up naming of old modules.

As for adding new builtins, that doesn't break old code. If you name a variable "next" in a function, the only problem you'll have with 2.6 is an inability to call the next() builtin from that function. The code will continue to work as before.

Now introducing new keywords to the language is another matter. The "with" keyword is the main one for 2.6, but developers had warning about that since 2.5 was released. Also, some keywords have been introduced such that they are only reserved in certain parser contexts (where this can be done unambiguously), allowing you to continue using them as variable names. They Python developers take this quite seriously.

What's new in Python 2.6

Posted Sep 3, 2008 11:43 UTC (Wed) by MiguelAtWork (guest, #53380) [Link]

I hadn't read PEP 8 before and I found it interesting, but it doesn't seem to help much with consistency in the use of underscores. New functions in 2.6 include such names as namedtuple, isgeneratorfunction or methodcaller on the no-underscores front, and ignore_patterns or create_connection on the other side. This still seems fairly random to me.

As for the comment about "next", I was thinking of code like this:

def old_function():
        global next
        next = "Hi!"

# ... 1000 lines of code here ...

def new_function(it):
        value = next(it)
I believe this would fail.

What's new in Python 2.6

Posted Sep 3, 2008 13:10 UTC (Wed) by amk (subscriber, #19) [Link]

Regarding the 'next' example: Yes, that code would crash, but that's not breaking *existing* code; you would have to add new code that used the next() built-in, and that would simply be a coding error. Existing applications that happen to use 'next' as a variable name should be OK.

What's new in Python 2.6

Posted Sep 3, 2008 16:16 UTC (Wed) by MiguelAtWork (guest, #53380) [Link]

I know, sorry I wasn't clear. The situation I was thinking of is one where you're updating an application written before 2.6 but you're unaware that the application redefines e.g. next. I don't think that's too far-fetched.

What's new in Python 2.6

Posted Sep 4, 2008 2:28 UTC (Thu) by jamesh (guest, #1159) [Link]

Assuming that the code has been broken up into reasonable sized modules, this isn't usually that big a deal. You can tackle the "Python 2.6 cleanness" problem on a module by module basis. A global next variable/function in one module isn't going to shadow the builtin in other modules.

Copyright © 2013, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds