You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Allow specifying SimpleNamespace attributes as a mapping/iterable in a positional argument #108191
It was discussed in the context of adding controversial AttrDict. The reason for adding AttrDict was to allow JSON object attributes to be accessed as Python object attributes rather than dict keys. The reason for not using SimpleNamespace for this was that you need to use a wrapper lambda x: SimpleNamespace(**x), which makes this solution less obvious.
Supporting a positional argument in SimpleNamespace(), which can be a mapping or an iterable of key-value pairs (like in the dict constructor) will make using SimpleNamespace with JSON more convenient.
SimpleNamespace({'a': 1, 'b': 2}) is the same as SimpleNamespace([('a', 1), ('b', 2)]) is the same as SimpleNamespace(a=1, b=2).
changed the title [-]Allow to specify SimpleNamespace attributes as a positional argument[/-][+]Allow specifying SimpleNamespace attributes as positional arguments[/+]on Aug 21, 2023
changed the title [-]Allow specifying SimpleNamespace attributes as positional arguments[/-][+]Allow specifying SimpleNamespace attributes as a mapping/iterable in a positional argument[/+]on Aug 21, 2023
Eric, is it compatible with your vision of SimpleNamespace?
If both answers are "yes", I'll merge the PR. If both answers are "no", I'll withdraw it and close the issue. If answers are mixed, we should have a discussion.
Activity
pythongh-108191: Add support of positional argument in SimpleNamespac…
pythongh-108191: Add support of positional argument in SimpleNamespac…
[-]Allow to specify SimpleNamespace attributes as a positional argument[/-][+]Allow specifying SimpleNamespace attributes as positional arguments[/+][-]Allow specifying SimpleNamespace attributes as positional arguments[/-][+]Allow specifying SimpleNamespace attributes as a mapping/iterable in a positional argument[/+]serhiy-storchaka commentedon Aug 26, 2023
@rhettinger, @ericsnowcurrently, I would like to know your opinion about this feature.
Raymond, would it be useful to you, in any way?
Eric, is it compatible with your vision of SimpleNamespace?
If both answers are "yes", I'll merge the PR. If both answers are "no", I'll withdraw it and close the issue. If answers are mixed, we should have a discussion.
ericsnowcurrently commentedon Aug 29, 2023
Yeah, I'm fine with this. It didn't seem worth it originally but it certainly isn't a bad thing.
gh-108191: Add support of positional argument in SimpleNamespace cons…
vstinner commentedon Apr 25, 2024
Congrats for landing this new feature.
serhiy-storchaka commentedon Apr 25, 2024
It is a minor feature. It was hanging for such long time only because I was not sure that it is worthy.