Skip to content

Commit

Permalink
Merge pull request #16 from erezsh/issue14
Browse files Browse the repository at this point in the history
Bugfix: No longer changing ForwardRef._evaluate, that interfered with…
  • Loading branch information
erezsh authored Dec 15, 2022
2 parents 00c9f7a + 37bc641 commit 115d901
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-latest
runs-on: ubuntu-20.04 # See https://github.com/actions/setup-python/issues/544
strategy:
matrix:
python-version: [3.6, 3.7, 3.8, 3.9, 3.10.0-rc - 3.10, pypy3]
Expand Down
17 changes: 16 additions & 1 deletion runtype/pytypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,21 @@
from . import base_types
from . import datetime_parse


if sys.version_info < (3, 9):
if sys.version_info < (3, 7):
# python 3.6
_orig_eval = ForwardRef._eval_type
else:
_orig_eval = ForwardRef._evaluate

def _forwardref_evaluate(self, g, l, _):
return _orig_eval(self, g, l)
else:
_forwardref_evaluate = ForwardRef._evaluate



py38 = sys.version_info >= (3, 8)


Expand Down Expand Up @@ -342,7 +357,7 @@ def _to_canon(self, t):
return t

if isinstance(t, ForwardRef):
t = t._evaluate(self.frame.f_globals, self.frame.f_locals, set())
t = _forwardref_evaluate(t, self.frame.f_globals, self.frame.f_locals, set())

if isinstance(t, tuple):
return SumType([to_canon(x) for x in t])
Expand Down
11 changes: 0 additions & 11 deletions runtype/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,9 @@
if sys.version_info < (3, 7):
# python 3.6
from typing import _ForwardRef as ForwardRef
_orig_eval = ForwardRef._eval_type
elif sys.version_info < (3, 9):
from typing import ForwardRef
_orig_eval = ForwardRef._evaluate
else:
from typing import ForwardRef

if sys.version_info < (3, 9):
def _evaluate(self, g, l, _):
return _orig_eval(self, g, l)
ForwardRef._evaluate = _evaluate



def get_func_signatures(typesystem, f):
sig = inspect.signature(f)
typesigs = []
Expand Down

0 comments on commit 115d901

Please sign in to comment.