[Python-Dev] Grammar change in classdef

Nick Coghlan ncoghlan at gmail.com
Sat Sep 16 19:28:48 CEST 2006

Fabio Zadrozny wrote:
> I've been porting the grammar for pydev to version 2.5 and I've seen
> that you can now declare a class in the format: class B():pass
> (without the testlist)
> -- from the grammar: classdef: 'class' NAME ['(' [testlist] ')'] ':' suite
> I think that this change should be presented at
> http://docs.python.org/dev/whatsnew/whatsnew25.html
> I'm saying that because I've only stumbled upon it by accident -- and
> I wasn't able to find any explanation on the reason or semantics of
> the change...

Lawrence already noted that this is already covered by the What's New document 
(semantically, it's identical to omitting the parentheses entirely).

As for the reason: it makes it possible to use the same style for classes 
without bases as is used for functions without arguments. Prior to this 
change, there was a sharp break in the class syntax, such that if you got rid 
of the last base class you had to get rid of the parentheses as well.


Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia

More information about the Python-Dev mailing list