10000 gh-108191: Add support of positional argument in SimpleNamespace constructor by serhiy-storchaka · Pull Request #108195 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

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

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Apr 24, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Apply suggestions from code review
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
  • Loading branch information
serhiy-storchaka and AA-Turner authored Aug 29, 2023
commit cf7ac97fcae88335f50d4169395aee88c16dcdb2
19 changes: 11 additions & 8 deletions Doc/library/types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -479,15 +479,18 @@ Additional Utility Classes and Functions
A simple :class:`object` subclass that provides attribute access to its
namespace, as well as a meaningful repr.

Unlike :class:`object`, with ``SimpleNamespace`` you can add and remove
Unlike :class:`object`, with :class:`!SimpleNamespace` you can add and remove
attributes.
The :class:`!SimpleNamespace` constructor can take a positional argument
which must be a mapping object with string keys or an :term:`iterable`
object producing key-value pairs with string keys.
Key-value pairs from the mapping object or the iterable object are
directly added to the underlying namespace.
If a ``SimpleNamespace`` object is initialized with keyword
arguments, those are directly added to the underlying namespace.

:py:class:`SimpleNamespace` objects may be initialized either
with keyword arguments or with a single positional argument.
When initialized with keyword arguments,
those are directly added to the underlying namespace.
Alternatively, when initialized with a positional argument,
the underlying namespace will be updated with key-value pairs
from that argument (either a mapping object or
an :term:`iterable` object producing key-value pairs).
All such keys must be strings.

The type is roughly equivalent to the following code::

Expand Down
0