python - Accepting integers as keys of **kwargs -


keywords have to strings

>>> def foo(**kwargs): ...     pass ...  >>> foo(**{0:0}) typeerror: foo() keywords must strings 

but black magic, namespaces able bypass that

>>> types import simplenamespace >>> simplenamespace(**{0:0}) namespace() 

why? , how? could implement python function can receive integers in kwargs mapping?

could implement python function can receive integers in kwargs mapping?

no, can't. python evaluation loop handles calling functions defined in python code differently calling callable object defined in c code. python evaluation loop code handles keyword argument expansion has firmly closed door on non-string keyword arguments.

but simplenamespace not python-defined callable, defined entirely in c code. accepts keyword arguments directly, without validation, why can pass in dictionary non-string keyword arguments.

that's perhaps bug; supposed use c-api argument parsing functions, guard against non-string keyword arguments. simplenamespace designed object holding sys.implementation data*, , wasn't designed other uses.

there might other such exceptions, they'll c-defined callables, not python functions.


* time.get_clock_info() method runs instance of simplenamespace class; it's other place type used.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -