From fe48f37bf7ebf293fb971722d39f7ece4a9eb9b8 Mon Sep 17 00:00:00 2001 From: Simon Lanzmich <48890288+slanzmich@users.noreply.github.com> Date: Sun, 3 Dec 2023 23:46:33 +0100 Subject: [PATCH] stdlib: Annotate `type.__prepare__` to return a mutable object (#11093) During class creation, the namespace returned by `__prepare__` is populated when the class body is executed. Therefore, it must be mutable. --- stdlib/builtins.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi index 92b5279bc..6d2e219e0 100644 --- a/stdlib/builtins.pyi +++ b/stdlib/builtins.pyi @@ -203,7 +203,7 @@ class type: def __instancecheck__(self, __instance: Any) -> bool: ... def __subclasscheck__(self, __subclass: type) -> bool: ... @classmethod - def __prepare__(metacls, __name: str, __bases: tuple[type, ...], **kwds: Any) -> Mapping[str, object]: ... + def __prepare__(metacls, __name: str, __bases: tuple[type, ...], **kwds: Any) -> MutableMapping[str, object]: ... if sys.version_info >= (3, 10): def __or__(self, __value: Any) -> types.UnionType: ... def __ror__(self, __value: Any) -> types.UnionType: ...