mirror of
https://github.com/python/cpython.git
synced 2025-09-15 05:06:12 +00:00
Issue #24635: Fixed flakiness in test_typing.py.
This commit is contained in:
parent
874dbe895d
commit
647bae6c52
3 changed files with 27 additions and 8 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue