-
Notifications
You must be signed in to change notification settings - Fork 285
Open
Labels
topic: featureDiscussions about new features for Python's type annotationsDiscussions about new features for Python's type annotations
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) find 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.
Metadata
Metadata
Assignees
Labels
topic: featureDiscussions about new features for Python's type annotationsDiscussions about new features for Python's type annotations