mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
bpo-44524: Fix cryptic TypeError message when trying to subclass special forms in typing (GH-27710)
This was a Python 3.9 regression.
(cherry picked from commit a3a4d20d67)
Co-authored-by: Yurii Karabas <1998uriyyo@gmail.com>
This commit is contained in:
parent
cd986e9031
commit
81fa08c5ea
3 changed files with 21 additions and 0 deletions
|
|
@ -2418,6 +2418,22 @@ def __new__(cls, arg):
|
|||
self.assertEqual(c.from_b, 'b')
|
||||
self.assertEqual(c.from_c, 'c')
|
||||
|
||||
def test_subclass_special_form(self):
|
||||
for obj in (
|
||||
ClassVar[int],
|
||||
Final[int],
|
||||
Union[int, float],
|
||||
Optional[int],
|
||||
Literal[1, 2],
|
||||
Concatenate[int, ParamSpec("P")],
|
||||
TypeGuard[int],
|
||||
):
|
||||
with self.subTest(msg=obj):
|
||||
with self.assertRaisesRegex(
|
||||
TypeError, f'^{re.escape(f"Cannot subclass {obj!r}")}$'
|
||||
):
|
||||
class Foo(obj):
|
||||
pass
|
||||
|
||||
class ClassVarTests(BaseTestCase):
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue