From 24fe4a20b4bd9b1fac22bfa5be23e84efc1688a8 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Thu, 30 Oct 2025 21:23:32 +0100 Subject: [PATCH 1/6] Change type.__dict__ to a proper attribute Closes: #11033 --- stdlib/builtins.pyi | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi index 1bc46493338c..e6072a733bc5 100644 --- a/stdlib/builtins.pyi +++ b/stdlib/builtins.pyi @@ -189,8 +189,9 @@ class type: __bases__: tuple[type, ...] @property def __basicsize__(self) -> int: ... - @property - def __dict__(self) -> types.MappingProxyType[str, Any]: ... # type: ignore[override] + # type.__dict__ is read-only at runtime, but that can't be expressed currently. + # See https://github.com/python/typeshed/issues/11033 for a discussion. + __dict__: ClassVar[types.MappingProxyType[str, Any]] # type: ignore[override] @property def __dictoffset__(self) -> int: ... @property From 646bc5312ced056b923dbb4a54ced75054a1e274 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Thu, 30 Oct 2025 21:24:54 +0100 Subject: [PATCH 2/6] Use Final --- stdlib/builtins.pyi | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi index e6072a733bc5..a98bb9f11689 100644 --- a/stdlib/builtins.pyi +++ b/stdlib/builtins.pyi @@ -42,6 +42,7 @@ from typing import ( # noqa: Y022,UP035 Any, BinaryIO, ClassVar, + Final, Generic, Mapping, MutableMapping, @@ -191,7 +192,7 @@ class type: def __basicsize__(self) -> int: ... # type.__dict__ is read-only at runtime, but that can't be expressed currently. # See https://github.com/python/typeshed/issues/11033 for a discussion. - __dict__: ClassVar[types.MappingProxyType[str, Any]] # type: ignore[override] + __dict__: Final[types.MappingProxyType[str, Any]] # type: ignore[override] @property def __dictoffset__(self) -> int: ... @property From dc2cf80dcd347507c489a5d41c3adc6b906232bc Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Thu, 30 Oct 2025 21:30:05 +0100 Subject: [PATCH 3/6] Fix type ignore --- stdlib/builtins.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi index a98bb9f11689..835ab3a74c44 100644 --- a/stdlib/builtins.pyi +++ b/stdlib/builtins.pyi @@ -192,7 +192,7 @@ class type: def __basicsize__(self) -> int: ... # type.__dict__ is read-only at runtime, but that can't be expressed currently. # See https://github.com/python/typeshed/issues/11033 for a discussion. - __dict__: Final[types.MappingProxyType[str, Any]] # type: ignore[override] + __dict__: Final[types.MappingProxyType[str, Any]] # type: ignore[assignment] @property def __dictoffset__(self) -> int: ... @property From aab30fb3a12f11638977fc7ab106edfec17c5af4 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Thu, 30 Oct 2025 21:32:36 +0100 Subject: [PATCH 4/6] Remove stubtest allowlist entry --- stdlib/@tests/stubtest_allowlists/common.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/stdlib/@tests/stubtest_allowlists/common.txt b/stdlib/@tests/stubtest_allowlists/common.txt index 1e50be185b03..d8956df6b327 100644 --- a/stdlib/@tests/stubtest_allowlists/common.txt +++ b/stdlib/@tests/stubtest_allowlists/common.txt @@ -237,7 +237,6 @@ asyncio.locks.Condition.release builtins.memoryview.__contains__ # C type that implements __getitem__ builtins.reveal_locals # Builtins that type checkers pretends exist builtins.reveal_type # Builtins that type checkers pretends exist -builtins.type.__dict__ # read-only but not actually a property; stubtest thinks it's a mutable attribute. # The following CodecInfo properties are added in __new__ codecs.CodecInfo.decode From 8b73781034c843d416d49603f18253d452521760 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Fri, 31 Oct 2025 17:02:51 +0100 Subject: [PATCH 5/6] Add test case --- stdlib/@tests/test_cases/builtins/check_type.py | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 stdlib/@tests/test_cases/builtins/check_type.py diff --git a/stdlib/@tests/test_cases/builtins/check_type.py b/stdlib/@tests/test_cases/builtins/check_type.py new file mode 100644 index 000000000000..48dcb7c97226 --- /dev/null +++ b/stdlib/@tests/test_cases/builtins/check_type.py @@ -0,0 +1,3 @@ +class Meta(type): ... + +call = Meta.__dict__['__call__'] From 6611d53dddfb717e75577b35302326da2990952d Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 31 Oct 2025 16:06:16 +0000 Subject: [PATCH 6/6] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stdlib/@tests/test_cases/builtins/check_type.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/stdlib/@tests/test_cases/builtins/check_type.py b/stdlib/@tests/test_cases/builtins/check_type.py index 48dcb7c97226..1eafcf482fb6 100644 --- a/stdlib/@tests/test_cases/builtins/check_type.py +++ b/stdlib/@tests/test_cases/builtins/check_type.py @@ -1,3 +1,4 @@ class Meta(type): ... -call = Meta.__dict__['__call__'] + +call = Meta.__dict__["__call__"]