Mypy crash on nested typeclasses
sobolevn opened this issue · 0 comments
sobolevn commented
This code:
from classes import typeclass
def some():
@typeclass
def a(instance) -> str:
...
@a.instance(int)
def _a_int(instance: int) -> str:
...
reveal_type(a)
Produces this crash:
» mypy ex.py --show-traceback
ex.py:8: error: INTERNAL ERROR -- Please try using mypy master on Github:
https://mypy.readthedocs.io/en/stable/common_issues.html#using-a-development-mypy-build
Please report a bug at https://github.com/python/mypy/issues
version: 0.902
Traceback (most recent call last):
File "mypy/checker.py", line 401, in accept
File "mypy/nodes.py", line 777, in accept
File "mypy/checker.py", line 3586, in visit_decorator
File "mypy/checkexpr.py", line 936, in check_call
File "mypy/checkexpr.py", line 917, in check_call
File "mypy/checkexpr.py", line 1029, in check_callable_call
File "mypy/checkexpr.py", line 738, in apply_function_plugin
File "/Users/sobolev/Documents/github/typeclasses/classes/contrib/mypy/features/typeclass.py", line 161, in __call__
typeclass, fullname = self._load_typeclass(ctx.type.args[1], ctx)
File "/Users/sobolev/Documents/github/typeclasses/classes/contrib/mypy/features/typeclass.py", line 207, in _load_typeclass
typeclass = type_loader.load_typeclass(
File "/Users/sobolev/Documents/github/typeclasses/classes/contrib/mypy/typeops/type_loader.py", line 35, in load_typeclass
typeclass_info = ctx.api.lookup_qualified(fullname) # type: ignore
File "mypy/checker.py", line 4747, in lookup_qualified
File "mypy/checker.py", line 4743, in lookup
KeyError: 'Failed lookup: a'
ex.py:8: : note: use --pdb to drop into pdb
We need to turn this into a typing error.