GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Allow specifying SimpleNamespace attributes as a mapping/iterable in a positional argument · Issue #108191 · python/cpython

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

New issue
Copy link
New issue
Copy link
Closed
Closed
Allow specifying SimpleNamespace attributes as a mapping/iterable in a positional argument#108191
Copy link
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancementA feature request or enhancement

Description

@serhiy-storchaka
serhiy-storchaka
opened on Aug 21, 2023
Issue body actions

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/[email protected]/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 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).

Linked PRs

  • gh-108191: Add support of positional argument in SimpleNamespace constructor #108195
Reacted by Erlend E. Aasland, Carl Meyer, Jean Abou Samra, Shantanu, Barney Gale, Ofek Lev, André Mello, Paarth Shah and Kent Matsuura

Activity

  1. serhiy-storchaka
    added
    type-featureA feature request or enhancementA feature request or enhancement
    on Aug 21, 2023
  2. serhiy-storchaka
    added 2 commits that reference this issue on Aug 21, 2023

    pythongh-108191: Add support of positional argument in SimpleNamespac…

    213c74d

    pythongh-108191: Add support of positional argument in SimpleNamespac…

    c761180
  3. CAM-Gerlach
    changed the title [-]Allow to specify SimpleNamespace attributes as a positional argument[/-] [+]Allow specifying SimpleNamespace attributes as positional arguments[/+] on Aug 21, 2023
  4. CAM-Gerlach
    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
  5. serhiy-storchaka commented on Aug 26, 2023

    @serhiy-storchaka
    serhiy-storchaka
    on Aug 26, 2023
    MemberAuthor
    More actions

    @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.

    Reacted by Erlend E. Aasland
    Reacted by Dima Tisnek
  6. ericsnowcurrently commented on Aug 29, 2023

    @ericsnowcurrently
    ericsnowcurrently
    on Aug 29, 2023
    Member
    More actions

    Yeah, I'm fine with this. It didn't seem worth it originally but it certainly isn't a bad thing.

  7. iritkatriel
    added
    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
    on Nov 27, 2023
  8. serhiy-storchaka
    added a commit that references this issue on Apr 24, 2024

    gh-108191: Add support of positional argument in SimpleNamespace cons…

    93b7ed7
  9. serhiy-storchaka
    closed this as completedon Apr 24, 2024
  10. vstinner commented on Apr 25, 2024

    @vstinner
    vstinner
    on Apr 25, 2024
    Member
    More actions

    Congrats for landing this new feature.

    Reacted by Eric Snow
  11. serhiy-storchaka commented on Apr 25, 2024

    @serhiy-storchaka
    serhiy-storchaka
    on Apr 25, 2024
    MemberAuthor
    More actions

    It is a minor feature. It was hanging for such long time only because I was not sure that it is worthy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.