From d2d2d76811c7d72a5052e0a002f01239711bec4d Mon Sep 17 00:00:00 2001 From: Michael Carlstrom Date: Sat, 20 Jul 2024 21:53:12 -0400 Subject: [PATCH] use getattr for < 3.9 --- mypy/stubgenc.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mypy/stubgenc.py b/mypy/stubgenc.py index 73d9a83b6fca..01f03e41dd5f 100755 --- a/mypy/stubgenc.py +++ b/mypy/stubgenc.py @@ -852,7 +852,7 @@ def generate_class_stub(self, class_name: str, cls: type, output: list[str]) -> if sys.version_info >= (3, 10): annotations = inspect.get_annotations(cls) else: - annotations = cls.__annotations__ + annotations = getattr(cls, '__annotations__', {}) for attr, value in attrs: if attr == "__hash__" and value is None: @@ -914,7 +914,7 @@ def generate_variable_stub(self, name: str, obj: object, output: list[str]) -> N if sys.version_info >= (3, 10): annotations = inspect.get_annotations(self.module) else: - annotations = self.module.__annotations__ + annotations = getattr(self.module, '__annotations__', {}) if name in annotations: type_str = self.strip_or_import(annotations[name])