Skip to content

gh-136140: Add update(**kwargs) method to types.SimpleNamespace #136142

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

TomasCorreia2003
Copy link

@TomasCorreia2003 TomasCorreia2003 commented Jun 30, 2025

Closes #136140

Summary

This PR adds an update(**kwargs) method to types.SimpleNamespace, allowing users to update the namespace's attributes in place using keyword arguments.

Example

from types import SimpleNamespace

ns = SimpleNamespace(a=1)
ns.update(b=2)
print(ns)  # namespace(a=1, b=2)

Why?
Improves usability by providing an intuitive way to update attributes

Avoids reliance on internal .__dict__ access

Matches expectations from dict.update()

Implementation Notes
Implemented in C (Objects/namespaceobject.c)

Uses PyDict_Update(self->__dict__, kwargs)

Supports inspect.signature() via __text_signature__

Unit test added to test_types.py




<!-- gh-issue-number: gh-136140 -->
* Issue: gh-136140
<!-- /gh-issue-number -->

@bedevere-app
Copy link

bedevere-app bot commented Jun 30, 2025

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

1 similar comment
@bedevere-app
Copy link

bedevere-app bot commented Jun 30, 2025

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@TomasCorreia2003 TomasCorreia2003 force-pushed the feature/simplenamespace-update branch from 5625bee to eebd2c0 Compare June 30, 2025 18:55
@bedevere-app
Copy link

bedevere-app bot commented Jun 30, 2025

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@ZeroIntensity ZeroIntensity changed the title Add update(**kwargs) method to types.SimpleNamespace gh-136140: Add update(**kwargs) method to types.SimpleNamespace Jul 1, 2025
@ZeroIntensity
Copy link
Member

The linked issue was closed, so this isn't going to be accepted.

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

Successfully merging this pull request may close these issues.

Proposal: Add update(**kwargs) method to types.SimpleNamespace
2 participants