Relax default overload subtyping checks
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Currently, mypy ensures monotnonically increasing order when testing overloads against overloads:
However, I believe (1) this rule does more harm than good in many cases when it is correct, and (2) there are many cases where it is incorrect. Therefore, I propose to move this check behind a new strictness flag and disable it by default. Later, one can see if the check can be refined to deal with the cases listed below.
Rationale
In https://github.com/python/typing/issues/2021 I showed that the current typing spec is too strict with respect to subtyping overloads.
When this check is incorrect
The check is incorrect when overloads are commutative, i.e. changing the overload order describes the same callable type. This is the case when:
-
Argument signatures are mutually exclusive mypy-playground
-
Argument types are mutually exclusive (e.g. via
@disjoint_bases) mypy-playground -
Argument types overlap, but return types are identical. mypy-playground
When this check is technically correct, but hurts in practice
As @disjoint_bases is relatively new, many libraries likely do not use it. Moreover, Intersection types are still not supported. Thus, many classes that are compatible at runtime cannot be put under the umbrella of a shared Protocol because inadvertently they will use different overload order at one point or another.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in mypy/subtypes.py at lines 1003-1009 and inspect how overloads are checked against overloads. Review the linked typing discussion and examples, then determine the strictness flag behavior and verify that the check is disabled by default while remaining available under the flag.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100