mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
gh-105280: Ensure isinstance([], collections.abc.Mapping)
always evaluates to False
(#105281)
This commit is contained in:
parent
058b960535
commit
08756dbba6
3 changed files with 38 additions and 8 deletions
|
@ -3,6 +3,7 @@ import collections
|
|||
import collections.abc
|
||||
from collections import defaultdict
|
||||
from functools import lru_cache, wraps
|
||||
import gc
|
||||
import inspect
|
||||
import itertools
|
||||
import pickle
|
||||
|
@ -2758,6 +2759,19 @@ class ProtocolTests(BaseTestCase):
|
|||
with self.assertRaisesRegex(TypeError, only_classes_allowed):
|
||||
issubclass(1, BadPG)
|
||||
|
||||
def test_isinstance_checks_not_at_whim_of_gc(self):
|
||||
self.addCleanup(gc.enable)
|
||||
gc.disable()
|
||||
|
||||
with self.assertRaisesRegex(
|
||||
TypeError,
|
||||
"Protocols can only inherit from other protocols"
|
||||
):
|
||||
class Foo(collections.abc.Mapping, Protocol):
|
||||
pass
|
||||
|
||||
self.assertNotIsInstance([], collections.abc.Mapping)
|
||||
|
||||
def test_issubclass_and_isinstance_on_Protocol_itself(self):
|
||||
class C:
|
||||
def x(self): pass
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue