diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2021-12-05 13:04:29 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-05 13:04:29 -0800 |
commit | abceb66c7e33d165361d8a26efb3770faa721aff (patch) | |
tree | d8cddf3e05dcc7782cfadedbed4184a8adb9ccb9 /Lib/test/test_dataclasses.py | |
parent | f1dd5ed1f35a7ed5c3833c822e9965de2400d77e (diff) | |
download | cpython-git-abceb66c7e33d165361d8a26efb3770faa721aff.tar.gz |
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 47075df8d5..ef5009ab11 100644 --- a/Lib/test/test_dataclasses.py +++ b/Lib/test/test_dataclasses.py @@ -8,6 +8,7 @@ import abc 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 @@ -1354,6 +1355,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. |