>>> class MyClass(): pass
>>> class MyClass: pass
>>> def my_func(): pass
>>> def my_func: pass
  File "<stdin>", line 1
    def my_func:
SyntaxError: invalid syntax


If only more of us grew up watching sesame street.

On Friday, February 1, 2013, Jason Keene wrote:
Both class and function definitions produce callable objects that are assigned to a name with nearly identical syntax.  I don't think your analogy with import/break statements is valid.  Additionally, both definitions produce very similar byte codes:

              3 MAKE_FUNCTION            0
              6 STORE_FAST               0 (my_func)

              9 MAKE_FUNCTION            0
             12 CALL_FUNCTION            0
             15 BUILD_CLASS         
             16 STORE_FAST               0 (MyClass)

The only argument I see for requiring empty parens in function definitions is a historical one.

On Thursday, January 31, 2013, Ben Finney wrote:
Jason Keene <jasonkeene@gmail.com> writes:

> In a way they do the same thing, they both create an object
> (function/class) from a suite and assign it to the name given after the
> keyword (def/class).  Sure they do totally different things with the suite
> in creating the object, but in essence it's a name assignment.

In a way, ‘import’ and ‘break’ do the same thing, they trigger the
compiler to compile a particular set of code bytes. Sure the code bytes
do totally different things, but in essence it's a statement.

Less facetiously: You can blur your vision as much as you like to make
‘class’ and ‘def’ look similar, but that doesn't diminish the importance
of the distinctions you're ignoring.

 \       “Always do right. This will gratify some people, and astonish |
  `\                                            the rest.” —Mark Twain |
_o__)                                                                  |
Ben Finney

Python-ideas mailing list