TLDR; This typing PEP proposes a way to specify a type parameter if omitted.
As far as I’m aware the only issue with the PEP from anyone in the typing community is about the way default
s for ParamSpec
s should be represented (Question about the representation of ParamSpec Generic classes · Issue #1274 · python/typing · GitHub).
Some previous discussion on typing-sig (Mailman 3 Defaults for TypeVar-likes - Typing-sig - python.org).
Some places this could be useful in the standard library:
-
collections.abc.Generator
- most people don’t use the last 2 type parameters, omitting them should be equivalent to collections.abc.Generator[T, None, None] or Any (I trust the opinions of the typeshed maintainers about this more than my own opinion here). -
builtins.slice
- Makeslice
generic over thestart
,stop
andstep
parameters.start
parameter should default toint
,stop
default to the type ofstart
andstep
default toint | None
. -
datetime.datetime
- for informing people of timezone awareness/naiveness at type time.default
andbound
should betimezone | None
.datetime[timezone]
would mean timezone-awaredatetime
s are expected to be passed,datetime[None]
means naivedatetime
s anddatetime[timezone | None]
means you don’t care about awareness. This is relatively commonplace in other languages’ datetime libraries. -
builtins.frozenset
-default
and potentiallybound
could be changed toHashable
to give better types and potentially catch more bugs before they reach production respectively.
Happy to answer any questions about this.