FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-108191: Add support of positional argument in SimpleNamespace constructor by serhiy-storchaka · Pull Request #108195 · python/cpython · GitHub

/ cpython Public

gh-108191: Add support of positional argument in SimpleNamespace constructor - #108195

Merged
serhiy-storchaka merged 17 commits into
python:mainfrom
serhiy-storchaka:SimpleNamespace-pos-arg
Apr 24, 2024
Merged

gh-108191: Add support of positional argument in SimpleNamespace constructor#108195
serhiy-storchaka merged 17 commits into
python:mainfrom
serhiy-storchaka:SimpleNamespace-pos-arg

Conversation

serhiy-storchaka commented Aug 21, 2023
edited by github-actions Bot
Loading

Copy link
Copy Markdown
Member

SimpleNamespace({'a': 1, 'b': 2}) and SimpleNamespace([('a', 1), ('b', 2)]) are now the same as SimpleNamespace(a=1, b=2).


📚 Documentation preview 📚: https://cpython-previews--108195.org.readthedocs.build/

…e constructor

SimpleNamespace({'a': 1, 'b': 2}) and SimpleNamespace([('a', 1), ('b', 2)])
are now the same as SimpleNamespace(a=1, b=2).
serhiy-storchaka force-pushed the SimpleNamespace-pos-arg branch from 213c74d to c761180 Compare August 21, 2023 07:44

carljm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This looks like a convenient option to provide in the constructor, with no downside, and established precedent in the dict constructor.

Comment thread Objects/namespaceobject.c Outdated
Comment thread Objects/namespaceobject.c Outdated
Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
Comment thread Objects/namespaceobject.c Outdated
Comment thread Objects/namespaceobject.c Outdated
Comment thread Objects/namespaceobject.c Outdated

erlend-aasland left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Thanks! The "polish" commit was a nice clean-up; it made the code more readable, IMO.

Comment thread Doc/library/types.rst Outdated
Comment thread Doc/library/types.rst Outdated
Comment thread Lib/test/test_types.py Outdated
Comment thread Doc/library/types.rst Outdated
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>

Copy link
Copy Markdown
Member

I have no real objections. I had considered doing this originally but figured it could wait. Here we are. 😄

rhettinger removed their request for review September 3, 2023 22:54
rhettinger self-assigned this Sep 7, 2023

Copy link
Copy Markdown
Member Author

I tried to implement SimpleNamespace.__replace__, and the code may be simpler with this feature:

args = (self.__dict__,)
return type(self)(*args, **kwargs)

instead of

d = {}
d.update(self.__dict__)
d.update(kwargs)
return type(self)(**d)

Copy link
Copy Markdown
Member Author

On other hand, I decided to use other way (#109175), which is more consistent with pickling and copying:

result = type(self)()
result.__dict__.update(self.__dict__)
result.__dict__.update(kwargs)
return result

So this is no longer a blocker.

bedevere-app Bot commented Jan 18, 2024

Copy link
Copy Markdown

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

Comment thread Doc/whatsnew/3.13.rst Outdated
serhiy-storchaka and others added 6 commits March 7, 2024 12:48
Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>

Copy link
Copy Markdown
Member Author

I have made the requested changes; please review again.

bedevere-app Bot commented Mar 7, 2024

Copy link
Copy Markdown

Thanks for making the requested changes!

@erlend-aasland, @ericsnowcurrently, @AA-Turner, @carljm: please review the changes made to this pull request.

ericsnowcurrently left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

LGTM

I left one comment about something mostly unrelated to this PR, so I don't consider it a blocker.

Comment thread Doc/library/types.rst

Copy link
Copy Markdown
Member Author

It would be good to get @rhettinger's feedback, but this PR already received many positive feedbacks, and I already invested in this issue so much, that I'm going to merge it anyway, even if initially I was not so interested in this.

carljm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Seems to be a reasonable amount of interest in this, and plenty of review approvals. Can we go ahead and merge for 3.13?

carljm commented Apr 24, 2024

Copy link
Copy Markdown
Member

Looks like a merge conflict needs to be resolved.

serhiy-storchaka merged commit 93b7ed7 into python:main Apr 24, 2024
serhiy-storchaka deleted the SimpleNamespace-pos-arg branch April 24, 2024 21:39
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants


Back | FazBrowse Home | New Git URL