Open asottile opened 3 months ago
Bisects to https://github.com/python/mypy/pull/17311 , looks like some weird partial type situation where mypy gets a partial type from the FUNCS[tp].append
but the type var scope there is different than the scope in ASTCallbackMapping.__getitem__
.
Definitely should at least have a better error message, a possible workaround is FUNCS = cast(ASTCallbackMapping, collections.defaultdict(list))
Another workaround is to make AST_T
a class-scoped type variable in the protocol definition:
class ASTCallbackMapping(Protocol[AST_T]):
def __getitem__(self, tp: type[AST_T]) -> list[ASTFunc[AST_T]]: ...
making the Protocol generic isn't right either because then visit
can't be typed properly -- the actual __getitem__
is what's generic, not the class itself
Bug Report
I've boiled down a minimal example -- this pattern is used by
pyupgrade
(andreorder-python-imports
) to register ast functions and has been working with mypy since version 0.710 -- but was broken with the last update sadlyTo Reproduce
this is a simplified version of pyupgrade/_data.py --
FUNCS
acts as a mapping from ast types to their callback functionsExpected Behavior
the behaviour pre-mypy-1.11:
(no errors)
Actual Behavior
the error message seems suspicious because I think those two are the same ?
Your Environment
mypy.ini
(and other config files): none