diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2021-12-05 21:25:43 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-05 21:25:43 (GMT) |
commit | 19050711f5a68e50b942b3b7f1f4cf398f27efff (patch) | |
tree | 37df214db3f2094eb3af2d0a6700dcdec590380c /Lib/test/test_dataclasses.py | |
parent | 52a9a71fe682e47f6c78a9c34aa9a797ca632c86 (diff) | |
download | cpython-19050711f5a68e50b942b3b7f1f4cf398f27efff.zip cpython-19050711f5a68e50b942b3b7f1f4cf398f27efff.tar.gz cpython-19050711f5a68e50b942b3b7f1f4cf398f27efff.tar.bz2 |
bpo-45663: Fix is_dataclass() for dataclasses which are subclasses of types.GenericAlias (GH-29294)
(cherry picked from commit 446be166861b2f08f87f74018113dd98ca5fca02)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Diffstat (limited to 'Lib/test/test_dataclasses.py')
-rw-r--r-- | Lib/test/test_dataclasses.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/Lib/test/test_dataclasses.py b/Lib/test/test_dataclasses.py index ad981d1..fa5adfc 100644 --- a/Lib/test/test_dataclasses.py +++ b/Lib/test/test_dataclasses.py @@ -7,6 +7,7 @@ from dataclasses import * import pickle import inspect import builtins +import types import unittest from unittest.mock import Mock from typing import ClassVar, Any, List, Union, Tuple, Dict, Generic, TypeVar, Optional, Protocol @@ -1348,6 +1349,17 @@ class TestCase(unittest.TestCase): with self.assertRaisesRegex(TypeError, 'should be called on dataclass instances'): replace(obj, x=0) + def test_is_dataclass_genericalias(self): + @dataclass + class A(types.GenericAlias): + origin: type + args: type + self.assertTrue(is_dataclass(A)) + a = A(list, int) + self.assertTrue(is_dataclass(type(a))) + self.assertTrue(is_dataclass(a)) + + def test_helper_fields_with_class_instance(self): # Check that we can call fields() on either a class or instance, # and get back the same thing. |