[Python-ideas] Default arguments in Python - the return - running out of ideas but...
Terry Reedy
tjreedy at udel.edu
Wed May 13 23:39:37 CEST 2009
Jeremy Banks wrote:
> To someone who's a novice to this, could someone explain to me why it
> has to be an existing keyword at all? Since not identifiers are valid
> in that context anyway, why couldn't it be a new keyword that can
> still be used as an identifier in valid contexts? For example (not
> that I advocate this choice of keyword at all):
>
> def foo(bar reinitialize_default []): # <-- it's a keyword here
> reinitialize_default = "It's an identifier here!"
>
> That would be a syntax error now and if it were defined as a keyword
> only in that context it wouldn't introduce backwards compatibility
> problems and wouldn't force us to reuse an existing keyword in a
> context that may be a bit of a stretch.
>
> Is there a reason that this wouldn't be a viable approach?
At one time, 'as' was only a keyword in the context of import.
So it is 'viable'. But it was a bit confusing for programmers and messy
implementation-wise and I think the developers were glad to promote 'as'
to a full keyword and would be reluctant to go down that road again.
More information about the Python-ideas
mailing list