mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-10 05:51:52 +08:00
Update types.SimpleNamespace for 3.13 (#12297)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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__
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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__
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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__
|
||||
|
||||
27
stdlib/@tests/test_cases/check_types.py
Normal file
27
stdlib/@tests/test_cases/check_types.py
Normal file
@@ -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
|
||||
@@ -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: ...
|
||||
|
||||
Reference in New Issue
Block a user