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

Steven D'Aprano steve at pearwood.info
Wed Jun 15 13:35:31 CEST 2011

Jacob Holm wrote:
> On 2011-06-15 02:28, Jan Kaliszewski wrote:

>>> -- 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.

This is another reason why function parameters should not be used for 
something that is not a function parameter!

+1 on the ability to inject locals into a function namespace.

-1 on having the syntax for that masquerade as function arguments.


More information about the Python-ideas mailing list