[Python-ideas] Definition Symmetry

MRAB python at mrabarnett.plus.com
Thu Jan 31 18:15:09 CET 2013


On 2013-01-31 16:35, Jason Keene wrote:
> Why do function definitions require parens?
>
>>>> class MyClass:
> ...     pass
> ...
>>>> def my_func:
>    File "<stdin>", line 1
>      def my_func:
>                 ^
> SyntaxError: invalid syntax
>
> This seems to me to break a symmetry with class definitions.  I assume
> this is just a hold off from C, perhaps there is a non-historical reason
> tho.
>
> I believe in the past we've forced parens in list comprehensions to
> create a symmetry between comprehensions/generator expressions.  Why not
> for this?
>
The parentheses are always required when calling the function, so it
makes sense to always require them when defining the function.

The case with class definitions is different; they are used in the
definition only when you want to specify the superclass.

They are always required when creating an instance of the class and in
method definitions.



More information about the Python-ideas mailing list