-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More principled approach for callable vs callable inference (#15910)
Fixes #702 (one of the oldest open issues) The approach is quite simple, I essentially replicate the logic from subtyping check, while replacing each `is_subtype()` call with `infer_constraints()` call. Note that we don't have various options available in `constraints.py` so I use all checks, even those that may be skipped with some strictness flags (so we can infer as many constraints as possible). Depending on the output of `mypy_primer` we can try to tune this. Note that while I was looking at subtyping code, I noticed couple inconsistencies for ParamSpecs, I added TODOs for them (and updated some existing TODOs). I also deleted some code that should be dead code after my previous cleanup. Among inconsistencies most notably, subtyping between `Parameters` uses wrong (opposite) direction. Normally, `Parameters` entity behaves covariantly (w.r.t. types of individual arguments) as a single big argument, like a tuple plus a map. But then this entity appears in a contravariant position in `Callable`. This is how we handle it in `constraints.py`, `join.py`, `meet.py` etc. I tried to fix the left/right order in `visit_parameters()`, but then one test failed (and btw same test would also fail if I would try to fix variance in `visit_instance()`). I decided to leave this for separate PR(s).
- Loading branch information
1 parent
e804e8d
commit 7141d6b
Showing
5 changed files
with
260 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.