Skip to content

Commit

Permalink
add version guard
Browse files Browse the repository at this point in the history
  • Loading branch information
InvincibleRMC committed Jul 21, 2024
1 parent 896b68a commit 70e4928
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions mypy/stubgenc.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import inspect
import keyword
import os.path
import sys
from types import FunctionType, ModuleType
from typing import Any, Callable, Mapping

Expand Down Expand Up @@ -848,7 +849,10 @@ def generate_class_stub(self, class_name: str, cls: type, output: list[str]) ->
attrs.append((attr, value))

# Gets annotations if they exist
annotations = inspect.get_annotations(cls)
if sys.version_info >= (3, 10):
annotations = inspect.get_annotations(cls)
else:
annotations = cls.__annotations__

for attr, value in attrs:
if attr == "__hash__" and value is None:
Expand Down Expand Up @@ -907,7 +911,10 @@ def generate_variable_stub(self, name: str, obj: object, output: list[str]) -> N
self.record_name(name)

# Gets annotations if they exist
annotations = inspect.get_annotations(self.module)
if sys.version_info >= (3, 10):
annotations = inspect.get_annotations(self.module)
else:
annotations = self.module.__annotations__

if name in annotations:
type_str = self.strip_or_import(annotations[name])
Expand Down

0 comments on commit 70e4928

Please sign in to comment.