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 — gh-108191: Add support of positional argument in SimpleNamespace constructor by serhiy-storchaka · Pull Request #108195 · python/cpython

Conversation

@serhiy-storchaka

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

Uh oh!

There was an error while loading. Please reload this page.

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

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

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

jaraco reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@serhiy-storchaka
serhiy-storchaka requested review from ericsnowcurrently and rhettinger August 21, 2023 07:39
@bedevere-bot bedevere-bot mentioned this pull request Aug 21, 2023
Allow specifying SimpleNamespace attributes as a mapping/iterable in a positional argument #108191
Closed
@bedevere-bot bedevere-bot added the awaiting core review label Aug 21, 2023
@serhiy-storchaka
pythongh-108191: Add support of positional argument in SimpleNamespac…
c761180
…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
serhiy-storchaka force-pushed the SimpleNamespace-pos-arg branch from 213c74d to c761180 Compare August 21, 2023 07:44
carljm
carljm approved these changes Aug 21, 2023
View reviewed changes

@carljm carljm left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this 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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

hauntsaninja and jaraco reacted with thumbs up emoji
All reactions
  • 👍 2 reactions
Comment thread Objects/namespaceobject.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot added awaiting merge and removed awaiting core review labels Aug 21, 2023
erlend-aasland
erlend-aasland reviewed Aug 22, 2023
View reviewed changes
Comment thread Objects/namespaceobject.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

@serhiy-storchaka @erlend-aasland
Update Objects/namespaceobject.c
06197a2
Co-authored-by: Erlend E. Aasland <[email protected]>
serhiy-storchaka
serhiy-storchaka commented Aug 22, 2023
View reviewed changes
Comment thread Objects/namespaceobject.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

erlend-aasland
erlend-aasland approved these changes Aug 22, 2023
View reviewed changes
serhiy-storchaka
serhiy-storchaka commented Aug 22, 2023
View reviewed changes
Comment thread Objects/namespaceobject.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

@serhiy-storchaka
Simplify the code.
1127a87
serhiy-storchaka
serhiy-storchaka commented Aug 24, 2023
View reviewed changes
Comment thread Objects/namespaceobject.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

serhiy-storchaka added 4 commits August 25, 2023 00:15
@serhiy-storchaka
Update Objects/namespaceobject.c
bc7ee1c
@serhiy-storchaka
Merge branch 'main' into SimpleNamespace-pos-arg
7338b2b
@serhiy-storchaka
Polishing.
e94e97a
@serhiy-storchaka
Extend tests.
f176567
erlend-aasland
erlend-aasland approved these changes Aug 26, 2023
View reviewed changes

@erlend-aasland erlend-aasland left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this 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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

ofek reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
AA-Turner
AA-Turner reviewed Aug 29, 2023
View reviewed changes
Comment thread Doc/library/types.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/library/types.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/test/test_types.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

AA-Turner
AA-Turner reviewed Aug 29, 2023
View reviewed changes
Comment thread Doc/library/types.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

@serhiy-storchaka @AA-Turner
Apply suggestions from code review
cf7ac97
Co-authored-by: Adam Turner <[email protected]>
AA-Turner
AA-Turner approved these changes Aug 29, 2023
View reviewed changes
@ericsnowcurrently

ericsnowcurrently commented Aug 29, 2023

Copy link
Copy Markdown
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
All reactions
  • 🎉 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

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

serhiy-storchaka commented Sep 9, 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)
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@serhiy-storchaka

serhiy-storchaka commented Sep 9, 2023

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the awaiting core review label Jan 18, 2024
@bedevere-app

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot added the awaiting changes label Jan 18, 2024
eendebakpt
eendebakpt reviewed Jan 18, 2024
View reviewed changes
Comment thread Doc/whatsnew/3.13.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

serhiy-storchaka and others added 6 commits March 7, 2024 12:48
@serhiy-storchaka @ericsnowcurrently @eendebakpt
Apply suggestions from code review
299d437
Co-authored-by: Eric Snow <[email protected]>
Co-authored-by: Pieter Eendebak <[email protected]>
@serhiy-storchaka
Merge branch 'main' into SimpleNamespace-pos-arg
3e9f572
@serhiy-storchaka
Update tests.
3c2002d
@serhiy-storchaka @ericsnowcurrently
Update Objects/namespaceobject.c
e7ad7be
Co-authored-by: Eric Snow <[email protected]>
@serhiy-storchaka
Extend errors tests.
772b708
@serhiy-storchaka
Fix typo.
54b2acf
@serhiy-storchaka

serhiy-storchaka commented Mar 7, 2024

Copy link
Copy Markdown
Member Author

I have made the requested changes; please review again.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot added awaiting change review and removed awaiting changes labels Mar 7, 2024
@bedevere-app

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app
bedevere-app Bot requested review from AA-Turner, carljm, ericsnowcurrently and erlend-aasland March 7, 2024 11:27
ericsnowcurrently
ericsnowcurrently approved these changes Mar 7, 2024
View reviewed changes

@ericsnowcurrently ericsnowcurrently left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this 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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Doc/library/types.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting change review labels Mar 7, 2024
erlend-aasland
erlend-aasland approved these changes Mar 7, 2024
View reviewed changes
@serhiy-storchaka

serhiy-storchaka commented Mar 8, 2024

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.

JelleZijlstra, erlend-aasland, ericsnowcurrently, and carljm reacted with thumbs up emoji
All reactions
  • 👍 4 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

carljm
carljm approved these changes Apr 24, 2024
View reviewed changes

@carljm carljm left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this 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?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

erlend-aasland, AA-Turner, and JelleZijlstra reacted with thumbs up emoji
All reactions
  • 👍 3 reactions
@carljm

carljm commented Apr 24, 2024

Copy link
Copy Markdown
Member

Looks like a merge conflict needs to be resolved.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@JelleZijlstra
Merge branch 'main' into SimpleNamespace-pos-arg
06b68ad
@serhiy-storchaka
serhiy-storchaka merged commit 93b7ed7 into python:main Apr 24, 2024
@bedevere-app bedevere-app Bot removed the awaiting merge label Apr 24, 2024
@serhiy-storchaka
serhiy-storchaka deleted the SimpleNamespace-pos-arg branch April 24, 2024 21:39
@max-muoto max-muoto mentioned this pull request Jul 9, 2024
Update types.SimpleNamespace for 3.13 python/typeshed#12297
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@eendebakpt eendebakpt eendebakpt left review comments
@carljm carljm carljm approved these changes
@ericsnowcurrently ericsnowcurrently ericsnowcurrently approved these changes
@erlend-aasland erlend-aasland erlend-aasland approved these changes
@rhettinger rhettinger Awaiting requested review from rhettinger
@AA-Turner AA-Turner Awaiting requested review from AA-Turner AA-Turner is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@rhettinger rhettinger

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

10 participants

@serhiy-storchaka @ericsnowcurrently @JelleZijlstra @AA-Turner @ofek @carljm @eendebakpt @erlend-aasland @rhettinger @bedevere-bot
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.