[Python-ideas] 'Injecting' objects as function-local constants

Jacob Holm jh at improva.dk
Wed Jun 15 08:21:47 CEST 2011

On 2011-06-15 02:28, Jan Kaliszewski wrote:
> Jan Kaliszewski dixit (2011-06-14, 12:17):
>> 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).

I disagree.  One of the main selling points of this feature for me is
that adding a few "hidden parameters" to a function does not change the
signature of the function.  If you raise a TypeError when the name of a
hidden parameter is in kwargs this is a change in signature.

- Jacob

More information about the Python-ideas mailing list