8000 Update `types.SimpleNamespace` for 3.13 by max-muoto · Pull Request #12297 · python/typeshed · GitHub
[go: up one dir, main page]

Skip to content

Update types.SimpleNamespace for 3.13 #12297

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 5 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 0 additions & 1 deletion stdlib/@tests/stubtest_allowlists/common.txt
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,6 @@ types.MethodType.__closure__ # read-only but not actually a property; stubtest
types.MethodType.__defaults__ # read-only but not actually a property; stubtest thinks it doesn't exist.
types.ModuleType.__dict__ # read-only but not actually a property; stubtest thinks it's a mutable attribute.
types.ModuleType.__getattr__ # this doesn't exist at runtime
types.SimpleNamespace.__init__ # class doesn't accept positional arguments but has default C signature

# sys attributes that are not always defined
sys.gettotalrefcount # Available on python debug builds
Expand Down
1 change: 1 addition & 0 deletions stdlib/@tests/stubtest_allowlists/py310.txt
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ pkgutil.ImpImporter\..*
pkgutil.ImpLoader\..*

types.CodeType.replace # stubtest thinks default values are None but None doesn't work at runtime
types.SimpleNamespace.__init__ # class doesn't accept positional arguments but has default C signature

# These enums derive from (str, Enum)
pstats.SortKey.__new__
Expand Down
1 change: 1 addition & 0 deletions stdlib/@tests/stubtest_allowlists/py311.txt
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ inspect._ParameterKind.description # Still exists, but stubtest can't see it
os.PathLike.__class_getitem__ # PathLike is a protocol; we don't expect all PathLike classes to implement class_getitem
poplib.POP3_SSL.stls # bad declaration of inherited function. See poplib.pyi
types.GenericAlias.__call__ # Would be complicated to fix properly, Any could silence problems. #6392
types.SimpleNamespace.__init__ # class doesn't accept positional arguments but has default C signature
types.GenericAlias.__getattr__
types.GenericAlias.__mro_entries__
weakref.ProxyType.__reversed__ # Doesn't really exist
Expand Down
3 changes: 3 additions & 0 deletions stdlib/@tests/stubtest_allowlists/py312.txt
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,9 @@ typing.ParamSpecKwargs.__mro_entries__
typing.TypeVar.__mro_entries__
typing.TypeVarTuple.__mro_entries__

# class doesn't accept positional arguments but has default C signature
types.SimpleNamespace.__init__

# TODO: mypy should infer that this attribute is inherited from builtins.type;
# why doesn't it infer this?
typing.SupportsAbs.__type_params__
Expand Down
1 change: 1 addition & 0 deletions stdlib/@tests/stubtest_allowlists/py38.txt
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ types.GetSetDescriptorType.__get__
types.MemberDescriptorType.__get__
types.MethodDescriptorType.__get__
types.WrapperDescriptorType.__get__
types.SimpleNamespace.__init__ # class doesn't accept positional arguments but has default C signature
multiprocessing.managers.DictProxy.clear
multiprocessing.managers.DictProxy.popitem

Expand Down
1 change: 1 addition & 0 deletions stdlib/@tests/stubtest_allowlists/py39.txt
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ pkgutil.ImpImporter\..*
pkgutil.ImpLoader\..*

types.CodeType.replace # stubtest thinks default values are None but None doesn't work at runtime
types.SimpleNamespace.__init__ # class doesn't accept positional arguments but has default C signature

# These enums derive from (str, Enum)
pstats.SortKey.__new__
Expand Down
27 changes: 27 additions & 0 deletions stdlib/@tests/test_cases/check_types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import sys
import types
from collections import UserDict

# test `types.SimpleNamespace`

# Valid:
types.SimpleNamespace()
types.SimpleNamespace(x=1, y=2)

if sys.version_info >= (3, 13):
types.SimpleNamespace(())
types.SimpleNamespace([])
types.SimpleNamespace([("x", "y"), ("z", 1)])
types.SimpleNamespace({})
types.SimpleNamespace(UserDict({"x": 1, "y": 2}))


# Invalid:
types.SimpleNamespace(1) # type: ignore
types.SimpleNamespace([1]) # type: ignore
types.SimpleNamespace([["x"]]) # type: ignore
types.SimpleNamespace(**{1: 2}) # type: ignore
types.SimpleNamespace({1: 2}) # type: ignore
types.SimpleNamespace([[1, 2]]) # type: ignore
types.SimpleNamespace(UserDict({1: 2})) # type: ignore
types.SimpleNamespace([[[], 2]]) # type: ignore
6 changes: 5 additions & 1 deletion stdlib/types.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,11 @@ class MappingProxyType(Mapping[_KT, _VT_co]):

class SimpleNamespace:
__hash__: ClassVar[None] # type: ignore[assignment]
def __init__(self, **kwargs: Any) -> None: ...
if sys.version_info >= (3, 13):
def __init__(self, mapping_or_iterable: Mapping[str, Any] | Iterable[tuple[str, Any]] = (), /, **kwargs: Any) -> None: ...
else:
def __init__(self, **kwargs: Any) -> None: ...

def __eq__(self, value: object, /) -> bool: ...
def __getattribute__(self, name: str, /) -> Any: ...
def __setattr__(self, name: str, value: Any, /) -> None: ...
Expand Down
Loading
0