[Python-ideas] 'Injecting' objects as function-local constants
zuo at chopin.edu.pl
Wed Jun 15 02:28:25 CEST 2011
Jan Kaliszewski dixit (2011-06-14, 12:17):
> It's obvious that such a repetition must be prohibited (SyntaxError, at
> compile time):
> def sth(my_var, **, my_var): "do something"
Of course, I ment:
def sth(my_var, **, my_var='foo'): "do something"
> But in case of:
> def sth(*args, **kwargs, my_var='foo'): "do something"
> -- should 'my_var' in kwargs be allowed? (it's a runtime question)
> There is no real conflict here, so at the first sight I'd say: yes.
On second thought: no, such repetitions also should *not* be allowed.
If a programmer, by mistake, would try to specify the argument value in
a call, an explicit TypeError should be raised -- otherwise it'd become
a trap (especially for beginners and absent-minded programmers).
More information about the Python-ideas