From 279293aaffd590670179420337e291290fb99d4f Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Thu, 10 Nov 2022 10:45:52 +0000 Subject: [PATCH 1/2] Improve `builtins.vars()` ```pycon >>> class Foo: ... ... >>> vars(Foo) mappingproxy({'__module__': '__main__', '__dict__': , '__weakref__': , '__doc__': None}) ``` --- stdlib/builtins.pyi | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi index d1204a0e189a..bcc379f6a175 100644 --- a/stdlib/builtins.pyi +++ b/stdlib/builtins.pyi @@ -1666,8 +1666,11 @@ else: @overload def sum(__iterable: Iterable[_AddableT1], __start: _AddableT2) -> _AddableT1 | _AddableT2: ... -# The argument to `vars()` has to have a `__dict__` attribute, so can't be annotated with `object` +# The argument to `vars()` has to have a `__dict__` attribute, so the second overload can't be annotated with `object` # (A "SupportsDunderDict" protocol doesn't work) +@overload +def vars(__object: type) -> types.MappingProxyType[str, Any]: ... +@overload def vars(__object: Any = ...) -> dict[str, Any]: ... class zip(Iterator[_T_co], Generic[_T_co]): From 5acda3a5d789927ae53f084ee6a48649c1de26cc Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Thu, 10 Nov 2022 10:49:29 +0000 Subject: [PATCH 2/2] Update stdlib/builtins.pyi --- stdlib/builtins.pyi | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi index bcc379f6a175..f7b1eb4b05a3 100644 --- a/stdlib/builtins.pyi +++ b/stdlib/builtins.pyi @@ -1668,8 +1668,9 @@ else: # The argument to `vars()` has to have a `__dict__` attribute, so the second overload can't be annotated with `object` # (A "SupportsDunderDict" protocol doesn't work) +# Use a type: ignore to make complaints about overlapping overloads go away @overload -def vars(__object: type) -> types.MappingProxyType[str, Any]: ... +def vars(__object: type) -> types.MappingProxyType[str, Any]: ... # type: ignore[misc] @overload def vars(__object: Any = ...) -> dict[str, Any]: ...