summaryrefslogtreecommitdiffstats
path: root/Lib/typing.py
diff options
context:
space:
mode:
authorYurii Karabas <1998uriyyo@gmail.com>2021-07-22 21:06:54 (GMT)
committerGitHub <noreply@github.com>2021-07-22 21:06:54 (GMT)
commit96c4cbd96c769e92869c62ba898dd9eb670baa81 (patch)
treebf57868bec1d475c469214d42f89d29158b60244 /Lib/typing.py
parentf1afef5e0d93d66fbf3c9aaeab8b3b8da9617583 (diff)
downloadcpython-96c4cbd96c769e92869c62ba898dd9eb670baa81.zip
cpython-96c4cbd96c769e92869c62ba898dd9eb670baa81.tar.gz
cpython-96c4cbd96c769e92869c62ba898dd9eb670baa81.tar.bz2
bpo-44353: Implement typing.NewType __call__ method in C (#27262)
Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com> Co-authored-by: Denis Laxalde <denis@laxalde.org>
Diffstat (limited to 'Lib/typing.py')
-rw-r--r--Lib/typing.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/Lib/typing.py b/Lib/typing.py
index 1aff0a1..5c95a4d 100644
--- a/Lib/typing.py
+++ b/Lib/typing.py
@@ -31,6 +31,13 @@ import types
import warnings
from types import WrapperDescriptorType, MethodWrapperType, MethodDescriptorType, GenericAlias
+
+try:
+ from _typing import _idfunc
+except ImportError:
+ def _idfunc(_, x):
+ return x
+
# Please keep __all__ alphabetized within each category.
__all__ = [
# Super-special typing primitives.
@@ -2375,6 +2382,8 @@ class NewType:
num = UserId(5) + 1 # type: int
"""
+ __call__ = _idfunc
+
def __init__(self, name, tp):
self.__name__ = name
self.__qualname__ = name
@@ -2384,9 +2393,6 @@ class NewType:
def __repr__(self):
return f'{self.__module__}.{self.__qualname__}'
- def __call__(self, x):
- return x
-
def __or__(self, other):
return Union[self, other]