summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2024-05-30 01:28:31 (GMT)
committerGitHub <noreply@github.com>2024-05-30 01:28:31 (GMT)
commit06c62d697a87822690342cd0d99d1cdbeca4ce9d (patch)
tree5c654d18a4cecf0af6e9d2ff7dc4570a834ee4d6 /Lib
parentaf57832e634720a797a54973a85d15ac3e13cf60 (diff)
downloadcpython-06c62d697a87822690342cd0d99d1cdbeca4ce9d.zip
cpython-06c62d697a87822690342cd0d99d1cdbeca4ce9d.tar.gz
cpython-06c62d697a87822690342cd0d99d1cdbeca4ce9d.tar.bz2
[3.13] gh-119260: Clarify is_dataclass Behavior for Subclasses in Documentation and Tests (GH-119480) (#119760)
gh-119260: Clarify is_dataclass Behavior for Subclasses in Documentation and Tests (GH-119480) (cherry picked from commit bf4ff3ad2e362801e87c85fffd9e140b774cef26) Co-authored-by: Aditya Borikar <adityaborikar2@gmail.com> Co-authored-by: Carl Meyer <carl@oddbird.net>
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_dataclasses/__init__.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/Lib/test/test_dataclasses/__init__.py b/Lib/test/test_dataclasses/__init__.py
index 04dd9f3..ffb8bbe 100644
--- a/Lib/test/test_dataclasses/__init__.py
+++ b/Lib/test/test_dataclasses/__init__.py
@@ -1547,6 +1547,24 @@ class TestCase(unittest.TestCase):
self.assertTrue(is_dataclass(type(a)))
self.assertTrue(is_dataclass(a))
+ def test_is_dataclass_inheritance(self):
+ @dataclass
+ class X:
+ y: int
+
+ class Z(X):
+ pass
+
+ self.assertTrue(is_dataclass(X), "X should be a dataclass")
+ self.assertTrue(
+ is_dataclass(Z),
+ "Z should be a dataclass because it inherits from X",
+ )
+ z_instance = Z(y=5)
+ self.assertTrue(
+ is_dataclass(z_instance),
+ "z_instance should be a dataclass because it is an instance of Z",
+ )
def test_helper_fields_with_class_instance(self):
# Check that we can call fields() on either a class or instance,