mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
bpo-41923: PEP 613: Add TypeAlias to typing module (#22532)
This special marker annotation is intended to help in distinguishing proper PEP 484-compliant type aliases from regular top-level variable assignments.
This commit is contained in:
parent
f90dc36c15
commit
4f3c25043d
6 changed files with 94 additions and 2 deletions
|
@ -113,6 +113,7 @@ __all__ = [
|
|||
'runtime_checkable',
|
||||
'Text',
|
||||
'TYPE_CHECKING',
|
||||
'TypeAlias',
|
||||
]
|
||||
|
||||
# The pseudo-submodules 're' and 'io' are part of the public
|
||||
|
@ -460,6 +461,21 @@ def Literal(self, parameters):
|
|||
return _GenericAlias(self, parameters)
|
||||
|
||||
|
||||
@_SpecialForm
|
||||
def TypeAlias(self, parameters):
|
||||
"""Special marker indicating that an assignment should
|
||||
be recognized as a proper type alias definition by type
|
||||
checkers.
|
||||
|
||||
For example::
|
||||
|
||||
Predicate: TypeAlias = Callable[..., bool]
|
||||
|
||||
It's invalid when used anywhere except as in the example above.
|
||||
"""
|
||||
raise TypeError(f"{self} is not subscriptable")
|
||||
|
||||
|
||||
class ForwardRef(_Final, _root=True):
|
||||
"""Internal wrapper to hold a forward reference."""
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue