diff options
author | Guido van Rossum <guido@dropbox.com> | 2015-09-04 12:15:54 -0700 |
---|---|---|
committer | Guido van Rossum <guido@dropbox.com> | 2015-09-04 12:15:54 -0700 |
commit | f937e2385982df623e61f9caad678c1d15825f5e (patch) | |
tree | 62f4e194acee2e58ee89139c54db64689dad110e /Lib/typing.py | |
parent | 16a761e4769b709490425e3b596acaaf3ebe46c8 (diff) | |
download | cpython-f937e2385982df623e61f9caad678c1d15825f5e.tar.gz |
Fix issue #24635.
Diffstat (limited to 'Lib/typing.py')
-rw-r--r-- | Lib/typing.py | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/Lib/typing.py b/Lib/typing.py index ddaec3e725..1a4982ead9 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 |