diff options
| author | Mikhail Golubev <qsolo825@gmail.com> | 2020-10-08 00:44:31 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-10-07 14:44:31 -0700 |
| commit | 4f3c25043d651a13c41cffcee703f7d5cb677cc7 (patch) | |
| tree | 08093971ec6aefd8b762e8da9d20434c09a3c3ae /Lib/typing.py | |
| parent | f90dc36c15d7fee0efaf6d39e97be0bdf2683e93 (diff) | |
| download | cpython-git-4f3c25043d651a13c41cffcee703f7d5cb677cc7.tar.gz | |
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.
Diffstat (limited to 'Lib/typing.py')
| -rw-r--r-- | Lib/typing.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/Lib/typing.py b/Lib/typing.py index 4cf33c1ae9..0f457ab1f5 100644 --- a/Lib/typing.py +++ b/Lib/typing.py @@ -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.""" |
