[issue22123] Make object() behave exactly like types.SimpleNamespace() if given kwargs
Serhiy Storchaka
report at bugs.python.org
Sat Aug 2 20:39:02 CEST 2014
Serhiy Storchaka added the comment:
This will be fragile because the behavior will be depend from the number of keyword argument. Hypothetic example:
>>> kwargs = {'a': 1}
>>> obj = object(**kwargs)
>>> obj.b = 2 # success
>>> kwargs = {} # empty
>>> obj = object(**kwargs)
>>> obj.b = 2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'object' object has no attribute 'b'
For now you need only one or two line of code to declare new class.
>>> class Object: pass
...
>>> obj = Object()
>>> obj.a = 1
>>> obj.b = 2
----------
nosy: +serhiy.storchaka
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue22123>
_______________________________________
More information about the Python-bugs-list
mailing list