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])