-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
1.11 regression: "generic" mapping failing with confusing error message #17566
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
Comments
Bisects to #17311 , looks like some weird partial type situation where mypy gets a partial type from the Definitely should at least have a better error message, a possible workaround is |
Another workaround is to make 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 |
Sorry if I'm missing something, but isn't this error expected? The protocol defines a "mapping from given type AST_T to a list of AST_T handlers corresponding to it". The problem: def visit(funcs: ASTCallbackMapping) -> None:
# Adding some exploding body
for callback in funcs[ast.And]:
callback(ast.And())
def handle_or(p: ast.Or) -> None:
assert isinstance(p, ast.Or)
store = collections.defaultdict(list)
store[ast.And] = [handle_or]
visit(store) Now There's nothing in static types of your original snippet preventing Note that you can't do FUNCS: collections.defaultdict[type[AST_T], list[Callable[[AST_T], None]]] = ... because |
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): noneThe text was updated successfully, but these errors were encountered: