mirror of
https://github.com/python/cpython.git
synced 2025-12-23 09:19:18 +00:00
[3.13] gh-105487: Fix __dir__ entries of GenericAlias (GH-138578) (#138640)
(cherry picked from commit b0420b505e)
Co-authored-by: Emma Smith <emma@emmatyping.dev>
This commit is contained in:
parent
614c493406
commit
d3b6bb1125
3 changed files with 44 additions and 6 deletions
|
|
@ -390,7 +390,10 @@ class BaseTest(unittest.TestCase):
|
|||
aliases = [
|
||||
GenericAlias(list, T),
|
||||
GenericAlias(deque, T),
|
||||
GenericAlias(X, T)
|
||||
GenericAlias(X, T),
|
||||
X[T],
|
||||
list[T],
|
||||
deque[T],
|
||||
] + _UNPACKED_TUPLES
|
||||
for alias in aliases:
|
||||
with self.subTest(alias=alias):
|
||||
|
|
@ -420,10 +423,26 @@ class BaseTest(unittest.TestCase):
|
|||
self.assertEqual(a.__parameters__, (T,))
|
||||
|
||||
def test_dir(self):
|
||||
dir_of_gen_alias = set(dir(list[int]))
|
||||
ga = list[int]
|
||||
dir_of_gen_alias = set(dir(ga))
|
||||
self.assertTrue(dir_of_gen_alias.issuperset(dir(list)))
|
||||
for generic_alias_property in ("__origin__", "__args__", "__parameters__"):
|
||||
self.assertIn(generic_alias_property, dir_of_gen_alias)
|
||||
for generic_alias_property in (
|
||||
"__origin__", "__args__", "__parameters__",
|
||||
"__unpacked__",
|
||||
):
|
||||
with self.subTest(generic_alias_property=generic_alias_property):
|
||||
self.assertIn(generic_alias_property, dir_of_gen_alias)
|
||||
for blocked in (
|
||||
"__bases__",
|
||||
"__copy__",
|
||||
"__deepcopy__",
|
||||
):
|
||||
with self.subTest(blocked=blocked):
|
||||
self.assertNotIn(blocked, dir_of_gen_alias)
|
||||
|
||||
for entry in dir_of_gen_alias:
|
||||
with self.subTest(entry=entry):
|
||||
getattr(ga, entry) # must not raise `AttributeError`
|
||||
|
||||
def test_weakref(self):
|
||||
for t in self.generic_types:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue