Skip to content

Commit

Permalink
try inspect.get_annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
InvincibleRMC committed Jul 21, 2024
1 parent e22b5b3 commit 896b68a
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions mypy/stubgenc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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])
Expand Down

0 comments on commit 896b68a

Please sign in to comment.