Skip to content

Commit

Permalink
Fix for Python 3.6
Browse files Browse the repository at this point in the history
  • Loading branch information
erezsh committed Oct 9, 2022
1 parent 533541d commit b0c8358
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
3 changes: 2 additions & 1 deletion runtype/dataclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
import random
from copy import copy
import dataclasses
from typing import Union, ForwardRef
from typing import Union
from abc import ABC, abstractmethod
import inspect

from .utils import ForwardRef
from .common import CHECK_TYPES
from .validation import TypeMismatchError, ensure_isa as default_ensure_isa
from .pytypes import TypeCaster, type_caster, SumType, NoneType
Expand Down
3 changes: 2 additions & 1 deletion runtype/pytypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import typing
from datetime import datetime

from .utils import ForwardRef
from .base_types import DataType, Validator, TypeMismatchError
from . import base_types
from . import datetime_parse
Expand Down Expand Up @@ -340,7 +341,7 @@ def _to_canon(self, t):
if isinstance(t, (base_types.Type, Validator)):
return t

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

if isinstance(t, tuple):
Expand Down
10 changes: 10 additions & 0 deletions runtype/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
import inspect

try:
from typing import ForwardRef
except ImportError:
# python 3.6
from typing import _ForwardRef as ForwardRef
def _evaluate(self, g, l, _):
return self._eval_type(g, l)
ForwardRef._evaluate = _evaluate


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

0 comments on commit b0c8358

Please sign in to comment.