Overlapping type
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 35/100
Research direction
Start with the overlapping-type examples in the issue and review the recent discussion they reference. Define the intended semantics for an Overlapping type, including unions, literals, and non-overlapping types; done means the behavior and typing rules are agreed upon.
Written by the indexing model from the issue text.
Description
This is an rough idea from the recent discussion of whether to use object/Any or _KT for arguments of certain methods like pop or __sub__. E.g.:
class MyPoppable[KT, VT]:
def pop(self, x: X) -> VT: ...
What should X be? Using KT (or KT | None) finds type errors like the following:
poppable: MyPoppable[str]
poppable.pop(123)
But has a problem with overlapping types:
def foo(x: int | str):
poppable.pop(x)
On the other hand, using object doesn't catch type errors like poppable.pop(123).
The solution would be able to specify that any partially overlapping type would be accepted:
class MyPoppable[KT, VT]:
def pop(self, x: Overlapping[KT]) -> VT: ...
MyPoppable[str]().pop() would accept str, str | None, Literal["x"], str | int, etc., but not e.g. plain int.
- Dominant language
- Python
- Stars
- 1.8k
- Forks
- 302
- Avg merge
- 23h
- Merged PRs (30d)
- 8
Contributor guide
No contributing guide indexed for this repository
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.
More from python/typing
-
topic: typing spec
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
topic: typing spec
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
topic: documentation
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
topic: documentation
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
-
topic: conformance tests topic: typing spec
Difficulty 3/5 1-2 days Newbie friendliness 72/100
Similar issues
-
Add: hunch Open
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
AbdelStark/awesome-typesafe#104 ·
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
DiamondLightSource/dodal#2211 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
openml/openml-python#1749 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
sipyourdrink-ltd/bernstein#6191 ·