summaryrefslogtreecommitdiffstats
path: root/Lib/typing.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@dropbox.com>2015-09-04 19:15:54 (GMT)
committerGuido van Rossum <guido@dropbox.com>2015-09-04 19:15:54 (GMT)
commit1b6691053701e92490c6b68171d6d6a645f8e708 (patch)
tree5a1606858b59e65eb698122f1019077c4353971e /Lib/typing.py
parent9f9a00afc028023cb67bc577606587fc163f7f2b (diff)
downloadcpython-1b6691053701e92490c6b68171d6d6a645f8e708.zip
cpython-1b6691053701e92490c6b68171d6d6a645f8e708.tar.gz
cpython-1b6691053701e92490c6b68171d6d6a645f8e708.tar.bz2
Fix issue #24635.
Diffstat (limited to 'Lib/typing.py')
-rw-r--r--Lib/typing.py15
1 files changed, 10 insertions, 5 deletions
diff --git a/Lib/typing.py b/Lib/typing.py
index ddaec3e..1a4982e 100644
--- a/Lib/typing.py
+++ b/Lib/typing.py
@@ -1,7 +1,3 @@
-# TODO:
-# - Generic[T, T] is invalid
-# - Look for TODO below
-
# TODO nits:
# Get rid of asserts that are the caller's fault.
# Docstrings (e.g. ABCs).
@@ -963,7 +959,8 @@ class GenericMeta(TypingMeta, abc.ABCMeta):
raise TypeError("Initial parameters must be "
"type variables; got %s" % p)
if len(set(params)) != len(params):
- raise TypeError("All type variables in Generic[...] must be distinct.")
+ raise TypeError(
+ "All type variables in Generic[...] must be distinct.")
else:
if len(params) != len(self.__parameters__):
raise TypeError("Cannot change parameter count from %d to %d" %
@@ -987,6 +984,14 @@ class GenericMeta(TypingMeta, abc.ABCMeta):
origin=self,
extra=self.__extra__)
+ def __instancecheck__(self, instance):
+ # Since we extend ABC.__subclasscheck__ and
+ # ABC.__instancecheck__ inlines the cache checking done by the
+ # latter, we must extend __instancecheck__ too. For simplicity
+ # we just skip the cache check -- instance checks for generic
+ # classes are supposed to be rare anyways.
+ return self.__subclasscheck__(instance.__class__)
+
def __subclasscheck__(self, cls):
if cls is Any:
return True