Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
KotlinIsland committed Aug 14, 2024
1 parent bd3566a commit f6a680d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
13 changes: 11 additions & 2 deletions basedtyping/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -680,10 +680,19 @@ def get_type_hints(
if value is None:
value = type(None)
if isinstance(value, str):
value = ForwardRef(value, is_argument=False, is_class=True)
# TODO: roll our own ForwardRef
if sys.version_info < (3,9):
value = ForwardRef(value, is_argument=False)
else:
value = ForwardRef(value, is_argument=False, is_class=True)
value = typing._eval_type(value, base_globals, base_locals)
hints[name] = value
return hints if include_extras else {k: typing._strip_annotations(t) for k, t in hints.items()}
if sys.version_info < (3,9):
def f(x):
return x
else:
f = typing._strip_annotations
return hints if include_extras else {k: f(t) for k, t in hints.items()}

if globalns is None:
if isinstance(obj, types.ModuleType):
Expand Down
6 changes: 4 additions & 2 deletions tests/test_get_type_hints.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from basedtyping import get_type_hints

def test_get_type_hints():
Expand All @@ -9,6 +11,6 @@ def __init_subclass__(cls, **kwargs):


class A(Base):
a: A | None
a: A

assert result == {'a': A | None}
assert result == {'a': A}

0 comments on commit f6a680d

Please sign in to comment.