matchawine / python-enforce-typing

An easy to use decorator to enforce static typing for function and dataclasses.
GNU General Public License v3.0
43 stars 6 forks source link

AttributeError: module 'typing' has no attribute '_SpecialForm' #8

Open DSLituiev opened 3 years ago

DSLituiev commented 3 years ago

running a simple example out of the box fails:

from typing import List
from enforce_typing import enforce_types

@enforce_types
def test(abc: List = []):
    return abc

test([])
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-3-0ef988ae29d7> in <module>
----> 1 test([])

/Applications/anaconda3/envs/slsl/lib/python3.6/site-packages/enforce_typing/decorator.py in wrapper(*args, **kwargs)
     26         @wraps(func)
     27         def wrapper(*args, **kwargs):
---> 28             check_types(*args, **kwargs)
     29             return func(*args, **kwargs)
     30 

/Applications/anaconda3/envs/slsl/lib/python3.6/site-packages/enforce_typing/decorator.py in check_types(*args, **kwargs)
     14             with suppress(KeyError):
     15                 type_hint = spec.annotations[name]
---> 16                 if isinstance(type_hint, typing._SpecialForm):
     17                     continue
     18                 actual_type = getattr(type_hint, "__origin__", type_hint)

AttributeError: module 'typing' has no attribute '_SpecialForm'

system

Python 3.6.7 | packaged by conda-forge | (default, Feb 28 2019, 02:16:08)
[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] on darwin