[Python-ideas] Fwd: Make parenthesis optional in parameterless functions definitions

Terry Reedy tjreedy at udel.edu
Thu Mar 31 14:06:39 EDT 2016


On 3/31/2016 12:29 PM, Mahan Marwat wrote:
Forwarded from Adnan Khan

> I have an idea of making parenthesis optional for functions having no
> parameters. i.e

I presume you mean only in function definitions and not in function calls.

> def greet: # note the missing parenthesis
>      print('hello')

-1  This will lead people to think even more often than they do now that 
they can omit () in the call.

> In Python we have already adopted this. i.e parenthesis are optional in
> `if` statements, in class definition, in tuple etc

Irrelevant.  *Every* expression can be optionally enclosed in ().  The 
() used to delimit the scope of operators is somewhat different from 
identifier(args) used to indicate a call and the scope of the argument list.

> if x == 1: # parenthesis are optional here
>      pass

They are optional because they are irrelevant.  The above is the same
as 'if ((((((((x==1)))))))):pass'.  The extraneous ()s are deleted.

However, greet() != greet(()) as the inner () is not deleted but passed 
as an empty tuple, which raises TypeError.

-- 
Terry Jan Reedy



More information about the Python-ideas mailing list