[Python-Dev] Requesting that a class be a new-style class

Michael Hudson mwh at python.net
Sat Feb 19 21:27:13 CET 2005

Nick Coghlan <ncoghlan at iinet.net.au> writes:

> This is something I've typed way too many times:
> Py> class C():
>    File "<stdin>", line 1
>      class C():
>              ^
> SyntaxError: invalid syntax
> It's the asymmetry with functions that gets to me - defining a
> function with no arguments still requires parentheses in the
> definition statement, but defining a class with no bases requires the
> parentheses to be omitted.

Yeah, this has annoyed me for ages too.

However!  You obviously haven't read Misc/HISTORY recently enough :)

The surprising thing is that "class C():" used to work (in fact before
0.9.4 the parens mandatory).  It became a syntax error in 0.9.9,
seemingly because Guido was peeved that people hadn't updated all
their old code to the new syntax.  I wonder if he'd like to try that
trick again today :)

I'd still vote for it to be changed.

> Which leads in to the real question: Does this *really* need to be a
> syntax error? Or could it be used as an easier way to spell "class
> C(object):"?

-1.  Too magical, too opaque.

> Then, in Python 3K, simply drop support for omitting the parentheses
> from class definitions - require inheriting from ClassicClass
> instead.

HISTORY repeats itself...


  [Perl] combines all the worst aspects of C and Lisp: a billion
  different sublanguages in one monolithic executable.  It combines
  the power of C with the readability of PostScript. -- Jamie Zawinski

More information about the Python-Dev mailing list