summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_genericalias.py
diff options
context:
space:
mode:
authorkj <28750310+Fidget-Spinner@users.noreply.github.com>2020-11-16 03:27:23 (GMT)
committerGitHub <noreply@github.com>2020-11-16 03:27:23 (GMT)
commit384b7a4bd988986bca227c7e85c32d766da74708 (patch)
treedbcb20fceb8d8e1f7e619b4007722b928c29c389 /Lib/test/test_genericalias.py
parentc272d40e5b7180861d4a97589855142d15e9ddf2 (diff)
downloadcpython-384b7a4bd988986bca227c7e85c32d766da74708.zip
cpython-384b7a4bd988986bca227c7e85c32d766da74708.tar.gz
cpython-384b7a4bd988986bca227c7e85c32d766da74708.tar.bz2
bpo-42332: Add weakref slot to types.GenericAlias (GH-23250)
Automerge-Triggered-By: GH:gvanrossum
Diffstat (limited to 'Lib/test/test_genericalias.py')
-rw-r--r--Lib/test/test_genericalias.py86
1 files changed, 48 insertions, 38 deletions
diff --git a/Lib/test/test_genericalias.py b/Lib/test/test_genericalias.py
index 2979cfb..912fb33 100644
--- a/Lib/test/test_genericalias.py
+++ b/Lib/test/test_genericalias.py
@@ -47,46 +47,46 @@ V = TypeVar('V')
class BaseTest(unittest.TestCase):
"""Test basics."""
+ generic_types = [type, tuple, list, dict, set, frozenset, enumerate,
+ defaultdict, deque,
+ SequenceMatcher,
+ dircmp,
+ FileInput,
+ OrderedDict, Counter, UserDict, UserList,
+ Pattern, Match,
+ partial, partialmethod, cached_property,
+ AbstractContextManager, AbstractAsyncContextManager,
+ Awaitable, Coroutine,
+ AsyncIterable, AsyncIterator,
+ AsyncGenerator, Generator,
+ Iterable, Iterator,
+ Reversible,
+ Container, Collection,
+ Callable,
+ Mailbox, _PartialFile,
+ ContextVar, Token,
+ Field,
+ Set, MutableSet,
+ Mapping, MutableMapping, MappingView,
+ KeysView, ItemsView, ValuesView,
+ Sequence, MutableSequence,
+ MappingProxyType, AsyncGeneratorType,
+ DirEntry,
+ chain,
+ TemporaryDirectory, SpooledTemporaryFile,
+ Queue, SimpleQueue,
+ _AssertRaisesContext,
+ SplitResult, ParseResult,
+ ValueProxy, ApplyResult,
+ WeakSet, ReferenceType, ref,
+ ShareableList, MPSimpleQueue,
+ Future, _WorkItem,
+ Morsel]
+ if ctypes is not None:
+ generic_types.extend((ctypes.Array, ctypes.LibraryLoader))
def test_subscriptable(self):
- types = [type, tuple, list, dict, set, frozenset, enumerate,
- defaultdict, deque,
- SequenceMatcher,
- dircmp,
- FileInput,
- OrderedDict, Counter, UserDict, UserList,
- Pattern, Match,
- partial, partialmethod, cached_property,
- AbstractContextManager, AbstractAsyncContextManager,
- Awaitable, Coroutine,
- AsyncIterable, AsyncIterator,
- AsyncGenerator, Generator,
- Iterable, Iterator,
- Reversible,
- Container, Collection,
- Callable,
- Mailbox, _PartialFile,
- ContextVar, Token,
- Field,
- Set, MutableSet,
- Mapping, MutableMapping, MappingView,
- KeysView, ItemsView, ValuesView,
- Sequence, MutableSequence,
- MappingProxyType, AsyncGeneratorType,
- DirEntry,
- chain,
- TemporaryDirectory, SpooledTemporaryFile,
- Queue, SimpleQueue,
- _AssertRaisesContext,
- SplitResult, ParseResult,
- ValueProxy, ApplyResult,
- WeakSet, ReferenceType, ref,
- ShareableList, MPSimpleQueue,
- Future, _WorkItem,
- Morsel]
- if ctypes is not None:
- types.extend((ctypes.Array, ctypes.LibraryLoader))
- for t in types:
+ for t in self.generic_types:
if t is None:
continue
tname = t.__name__
@@ -293,5 +293,15 @@ class BaseTest(unittest.TestCase):
for generic_alias_property in ("__origin__", "__args__", "__parameters__"):
self.assertIn(generic_alias_property, dir_of_gen_alias)
+ def test_weakref(self):
+ for t in self.generic_types:
+ if t is None:
+ continue
+ tname = t.__name__
+ with self.subTest(f"Testing {tname}"):
+ alias = t[int]
+ self.assertEqual(ref(alias)(), alias)
+
+
if __name__ == "__main__":
unittest.main()