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

Fault in typecheck agent on checking return type in presence of self or classmethod's cls #63

Closed jolaf closed 5 years ago

jolaf commented 5 years ago

The following trivial code:

from configparser import ConfigParser
from pytypes import TypeChecker

with TypeChecker():
    ConfigParser()

fails as follows:

$ python3 Test.py
/usr/local/lib/python3.6/dist-packages/pytypes/type_util.py:2399: UserWarning: the system profiling hook has changed unexpectedly
  warn('the system profiling hook has changed unexpectedly')
Traceback (most recent call last):
  File "Test.py", line 5, in <module>
    ConfigParser()
  File "/usr/lib/python3.6/configparser.py", line 612, in __init__
    self._proxies[default_section] = SectionProxy(self, default_section)
  File "/usr/lib/python3.6/configparser.py", line 1223, in __init__
    for conv in parser.converters:
  File "/usr/lib/python3.6/configparser.py", line 1181, in converters
    return self._converters
  File "/usr/local/lib/python3.6/dist-packages/pytypes/type_util.py", line 2446, in __call__
    _check_caller_type(True, None, arg, caller_level=self._caller_level_shift+1)
  File "/usr/local/lib/python3.6/dist-packages/pytypes/type_util.py", line 2247, in _check_caller_type
    orig_clss = call_args[0].__orig_class__
  File "/usr/lib/python3.6/configparser.py", line 1306, in __getitem__
    return self._data[key]
KeyError: 0
Stewori commented 5 years ago

On vacation at the moment. I will have a look next week.

jolaf commented 5 years ago

Thanks!

Stewori commented 5 years ago

There is a fault in the typecheck profiler when checking a subscriptable return type in presence of self. (Would be triggered also by a @classmethod concerning cls).

from pytypes import TypeChecker

class A:
    def testmeth_agent_err(self) -> int:
        return {}

a = A()
with TypeChecker():
    a.testmeth_agent_err()
jolaf commented 5 years ago

Thanks!