Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in @typechecked with List[Dict[str, str]] #92

Open
leo-deprecated opened this issue Jul 31, 2020 · 1 comment
Open

Error in @typechecked with List[Dict[str, str]] #92

leo-deprecated opened this issue Jul 31, 2020 · 1 comment

Comments

@leo-deprecated
Copy link

environment

  • python 3.6.8
  • windows 10, linux 18.04 LTS

function definition

from pytypes import typechecked
from typing import List, Dict

@typechecked
def func(x:List[Dict[str, str]]):
    do sth else

test with unittest

x = [
  {
    'a':'a'
  }
]
func(x=x)

raise error

ERROR: test (__main__.test)
----------------------------------------------------------------------
Traceback (most recent call last):
  File 
    func(x=x)
  File "c:\python\py36\lib\site-packages\pytypes\typechecker.py", line 858, in checker_tp
    prop_getter or auto_prop_getter, specs, bound_typevars=bound_typevars)
  File "c:\python\py36\lib\site-packages\pytypes\typechecker.py", line 685, in _checkfunctype
    _recursion_check, True, func)
  File "c:\python\py36\lib\site-packages\pytypes\typechecker.py", line 585, in _checkinstance
    is_args, func)
  File "c:\python\py36\lib\site-packages\pytypes\typechecker.py", line 671, in _checkinstance
    bound_typevars_readonly, follow_fwd_refs, _recursion_check), obj
  File "c:\python\py36\lib\site-packages\pytypes\type_util.py", line 1904, in _isinstance
    bound_typevars_readonly, follow_fwd_refs, _recursion_check)
  File "c:\python\py36\lib\site-packages\pytypes\type_util.py", line 1769, in _issubclass
    bound_typevars_readonly, follow_fwd_refs, _recursion_check)
  File "c:\python\py36\lib\site-packages\pytypes\type_util.py", line 1799, in _issubclass_2
    bound_typevars_readonly, follow_fwd_refs, _recursion_check)
  File "c:\python\py36\lib\site-packages\pytypes\type_util.py", line 1341, in _issubclass_Generic
    _recursion_check):
  File "c:\python\py36\lib\site-packages\pytypes\type_util.py", line 1769, in _issubclass
    bound_typevars_readonly, follow_fwd_refs, _recursion_check)
  File "c:\python\py36\lib\site-packages\pytypes\type_util.py", line 1796, in _issubclass_2
    _recursion_check)
  File "c:\python\py36\lib\site-packages\pytypes\type_util.py", line 1140, in _issubclass_Mapping_covariant
    return issubclass(subclass, superclass)
  File "C:\Program Files\Python36\lib\typing.py", line 1148, in __subclasscheck__
    raise TypeError("Parameterized generics cannot be used with class "
TypeError: Parameterized generics cannot be used with class or instance checks

why this error raised??
i'm hard to find the reason

@Stewori
Copy link
Owner

Stewori commented Aug 1, 2020

Sorry, but I cannot reproduce this issue. However, I did not test with Python 3.6.8 specifically, but before I undertake the hassle to setup this specific version on my system I would like to exclude other possible causes (because I somewhat doubt that Python 3.6.8 is the cause).
If I run

from pytypes import typechecked
from typing import List, Dict

@typechecked
def func(x: List[Dict[str, str]]):
	pass

x = [
  {
    'a': 'a'
  }
]

func(x=7)

that works as expected. What do you mean by "unittest"? What tests do you refer to?
Anyway, please post an entire runnable code snippet you think that fails, e.g. similar to that I posted above. If there's more to it than just running python file.py, please describe how to run it such that it fails.
What version of pytypes are you using?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants