Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Allow specifying SimpleNamespace attributes as a mapping/iterable in a positional argument #108191

Closed
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancement
@serhiy-storchaka

Description

@serhiy-storchaka

Feature or enhancement

Has this already been discussed elsewhere?

I have already discussed this feature proposal on Discourse

Links to previous discussion of this feature:

#96145
https://mail.python.org/archives/list/python-dev@python.org/message/TYIXRGOLWGV5TNJ3XMV443O3RWLEYB65/

Proposal:

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 wrapperlambda x: SimpleNamespace(**x), which makes this solution less obvious.

Supporting a positional argument inSimpleNamespace(), which can be a mapping or an iterable of key-value pairs (like in thedict constructor) will make using SimpleNamespace with JSON more convenient.

SimpleNamespace({'a': 1, 'b': 2}) is the same asSimpleNamespace([('a', 1), ('b', 2)]) is the same asSimpleNamespace(a=1, b=2).

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp