This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author serhiy.storchaka
Recipients serhiy.storchaka, vstinner
Date 2017-10-01.06:36:40
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1506839802.01.0.213398074469.issue31655@psf.upfronthosting.co.za>
In-reply-to
Content
Usually non-string keyword names are rejected.

>>> def f(**kwargs): pass                                                                                                                                                                                                                    
...                                                                                                                                                                                                                                          
>>> f(**{0:0})
Traceback (most recent call last):                                                                                                                                                                                                           
  File "<stdin>", line 1, in <module>                                                                                                                                                                                                        
TypeError: f() keywords must be strings                                                                                                                                                                                                      
>>> dict(**{0:0})
Traceback (most recent call last):                                                                                                                                                                                                           
  File "<stdin>", line 1, in <module>                                                                                                                                                                                                        
TypeError: keywords must be strings                                                                                                                                                                                                          

There are checks in multiple places that satisfy this: in _PyEval_EvalCodeWithName(), PyArg_ValidateKeywordArguments(), PyArg_ParseTupleAndKeywords(), etc.

But SimpleNamespace is an exception.

>>> from types import SimpleNamespace
>>> SimpleNamespace(**{0:0})
namespace()

Non-string keys are omitted in the repr. Wouldn't be better to add also the check that keyword names for SimpleNamespace constructor are strings?

I don't know how classify this issue, as a bug or an enhancement.

Based on the StackOverflow question: https://stackoverflow.com/questions/46164770/accepting-integers-as-keys-of-kwargs.
History
Date User Action Args
2017-10-01 06:36:42serhiy.storchakasetrecipients: + serhiy.storchaka, vstinner
2017-10-01 06:36:42serhiy.storchakasetmessageid: <1506839802.01.0.213398074469.issue31655@psf.upfronthosting.co.za>
2017-10-01 06:36:41serhiy.storchakalinkissue31655 messages
2017-10-01 06:36:40serhiy.storchakacreate