Stewori / pytypes

Typing-toolbox for Python 3 _and_ 2.7 w.r.t. PEP 484.
Apache License 2.0
200 stars 20 forks source link

AttributeError: 'NoneType' object has no attribute '__bound__' #120

Closed iperov closed 1 year ago

iperov commented 1 year ago
from typing import Set, Generic, TypeVar
import pytypes

T = TypeVar('T')
class Value(Generic[T]):
    @pytypes.typechecked
    def __init__(self, initial : T):
        ...

Value[Set]( set([1,2,3]) )

error:

Traceback (most recent call last):
  File "_internal\github_project\main.py", line 227, in <module>
    Value[Set]( set([1,2,3]) )
  File "typing.py", line 729, in __call__
  File "D:\DevelopPPP\projects\InterBox\_internal\python\lib\site-packages\pytypes\typechecker.py", line 858, in checker_tp
    checked_val = _checkfunctype(argSig, check_args,
  File "D:\DevelopPPP\projects\InterBox\_internal\python\lib\site-packages\pytypes\typechecker.py", line 688, in _checkfunctype
    result, checked_val = _checkinstance(check_val, argSig,
  File "D:\DevelopPPP\projects\InterBox\_internal\python\lib\site-packages\pytypes\typechecker.py", line 581, in _checkinstance
    res, obj2 = _checkinstance(obj[i], prms[0 if elps else i], bound_Generic, bound_typevars,
  File "D:\DevelopPPP\projects\InterBox\_internal\python\lib\site-packages\pytypes\typechecker.py", line 675, in _checkinstance
    return _isinstance(obj, cls, bound_Generic, bound_typevars,
  File "D:\DevelopPPP\projects\InterBox\_internal\python\lib\site-packages\pytypes\type_util.py", line 2164, in _isinstance
    return _issubclass(deep_type(obj), cls, bound_Generic, bound_typevars,
  File "D:\DevelopPPP\projects\InterBox\_internal\python\lib\site-packages\pytypes\type_util.py", line 1992, in _issubclass
    return _issubclass(subclass, superclass, bound_Generic, bound_typevars,
  File "D:\DevelopPPP\projects\InterBox\_internal\python\lib\site-packages\pytypes\type_util.py", line 2019, in _issubclass
    res = _issubclass_2(subclass, superclass, bound_Generic, bound_typevars,
  File "D:\DevelopPPP\projects\InterBox\_internal\python\lib\site-packages\pytypes\type_util.py", line 2051, in _issubclass_2
    return _issubclass_Generic(subclass, superclass, bound_Generic, bound_typevars,
  File "D:\DevelopPPP\projects\InterBox\_internal\python\lib\site-packages\pytypes\type_util.py", line 1582, in _issubclass_Generic
    if not _issubclass(p_self, p_cls, bound_Generic, bound_typevars,
  File "D:\DevelopPPP\projects\InterBox\_internal\python\lib\site-packages\pytypes\type_util.py", line 2015, in _issubclass
    if not subclass.__bound__ is None:
AttributeError: 'NoneType' object has no attribute '__bound__'
Stewori commented 1 year ago

Does it work for Value[Set[List[int]]]( set([1,2,3]) )?

iperov commented 1 year ago
  called with incompatible types:
Expected: Tuple[Set[List[int]]]
Received: Tuple[Set[int]]
iperov commented 1 year ago

set([1,2,3]) makes set from iterable of list of values

iperov commented 1 year ago

but Value[Set[int]]( set([1,2,3]) ) works.

iperov commented 1 year ago

can you fix Set of undefined values?