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

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

serhiy-storchaka
Copy link
Member

@serhiy-storchakaserhiy-storchaka commentedAug 21, 2023
edited by github-actionsbot
Loading

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/

jaraco reacted with thumbs up emoji
…e constructorSimpleNamespace({'a': 1, 'b': 2}) and SimpleNamespace([('a', 1), ('b', 2)])are now the same as SimpleNamespace(a=1, b=2).
Copy link
Member

@carljmcarljm left a comment

Choose a reason for hiding this comment

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

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

hauntsaninja and jaraco reacted with thumbs up emoji
Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
Copy link
Contributor

@erlend-aaslanderlend-aasland left a comment

Choose a reason for hiding this comment

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

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

ofek reacted with thumbs up emoji
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
@ericsnowcurrently
Copy link
Member

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

erlend-aasland reacted with hooray emoji

@rhettingerrhettinger removed their request for reviewSeptember 3, 2023 22:54
@rhettingerrhettinger self-assigned thisSep 7, 2023
@serhiy-storchaka
Copy link
MemberAuthor

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

args= (self.__dict__,)returntype(self)(*args,**kwargs)

instead of

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

@serhiy-storchaka
Copy link
MemberAuthor

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)returnresult

So this is no longer a blocker.

@bedevere-app
Copy link

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

serhiy-storchakaand others added6 commitsMarch 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>
@serhiy-storchaka
Copy link
MemberAuthor

I have made the requested changes; please review again.

@bedevere-app
Copy link

Thanks for making the requested changes!

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

Copy link
Member

@ericsnowcurrentlyericsnowcurrently left a comment

Choose a reason for hiding this comment

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

LGTM

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

@serhiy-storchaka
Copy link
MemberAuthor

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.

JelleZijlstra, erlend-aasland, ericsnowcurrently, and carljm reacted with thumbs up emoji

Copy link
Member

@carljmcarljm left a comment

Choose a reason for hiding this comment

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

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

erlend-aasland, AA-Turner, and JelleZijlstra reacted with thumbs up emoji
@carljm
Copy link
Member

Looks like a merge conflict needs to be resolved.

@serhiy-storchakaserhiy-storchaka merged commit93b7ed7 intopython:mainApr 24, 2024
36 checks passed
@serhiy-storchakaserhiy-storchaka deleted the SimpleNamespace-pos-arg branchApril 24, 2024 21:39
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@eendebakpteendebakpteendebakpt left review comments

@carljmcarljmcarljm approved these changes

@ericsnowcurrentlyericsnowcurrentlyericsnowcurrently approved these changes

@erlend-aaslanderlend-aaslanderlend-aasland approved these changes

@rhettingerrhettingerAwaiting requested review from rhettinger

@AA-TurnerAA-TurnerAwaiting requested review from AA-Turner

Assignees

@rhettingerrhettinger

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

10 participants
@serhiy-storchaka@ericsnowcurrently@JelleZijlstra@AA-Turner@ofek@carljm@eendebakpt@erlend-aasland@rhettinger@bedevere-bot

[8]ページ先頭

©2009-2025 Movatter.jp