From 896b68a93623c69707556f5959d239b0ae98a8f8 Mon Sep 17 00:00:00 2001 From: Michael Carlstrom Date: Sat, 20 Jul 2024 21:45:27 -0400 Subject: [PATCH] try inspect.get_annotations --- mypy/stubgenc.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/mypy/stubgenc.py b/mypy/stubgenc.py index 94468cb36dff..a44acc303228 100755 --- a/mypy/stubgenc.py +++ b/mypy/stubgenc.py @@ -848,10 +848,7 @@ def generate_class_stub(self, class_name: str, cls: type, output: list[str]) -> attrs.append((attr, value)) # Gets annotations if they exist - try: - annotations = cls.__annotations__ - except AttributeError: - annotations = {} + annotations = inspect.get_annotations(cls) for attr, value in attrs: if attr == "__hash__" and value is None: @@ -910,10 +907,7 @@ def generate_variable_stub(self, name: str, obj: object, output: list[str]) -> N self.record_name(name) # Gets annotations if they exist - try: - annotations = self.module.__annotations__ - except AttributeError: - annotations = {} + annotations = inspect.get_annotations(self.module) if name in annotations: type_str = self.strip_or_import(annotations[name])