8000 Save progress · python/cpython@0e9b25c · GitHub
[go: up one dir, main page]

Skip to content

Commit 0e9b25c

Browse files
committed
Save progress
1 parent 8d46f25 commit 0e9b25c

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

Doc/library/dataclasses.rst

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -461,9 +461,8 @@ Module contents
461461

462462
.. function:: is_dataclass(obj)
463463

464-
Return ``True`` if its parameter is a dataclass, an instance of a dataclass,
465-
or a subclass of a dataclass, otherwise return ``False``. Note that subclasses
466-
of dataclasses inherit the properties of the dataclass so will return ``True``.
464+
Return ``True`` if its parameter is a dataclass (including subclasses of a dataclass)
465+
or an instance of one, otherwise return ``False``.
467466

468467
If you need to know if a class is an instance of a dataclass (and
469468
not a dataclass itself), then add a further check for ``not

Lib/test/test_dataclasses/__init__.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1555,16 +1555,15 @@ class X:
15551555
y: int
15561556

15571557
class Z(X):
1558-
z: int = 0 # Adding a default field to demonstrate inheritance and dataclass behavior
1558+
pass
15591559

1560-
# Check if X is a dataclass
1560+
# Assert that both X and Z are recognized as dataclasses
15611561
self.assertTrue(is_dataclass(X), "X should be a dataclass")
1562-
# Check if Z is a dataclass, it should inherit the dataclass behavior from X
15631562
self.assertTrue(is_dataclass(Z), "Z should be a dataclass because it inherits from X")
1564-
# Create an instance of Z and check if the default values are set correctly
1563+
1564+
# Instantiate Z and verify it is recognized as a dataclass
15651565
z_instance = Z(y=5)
1566-
self.assertEqual(z_instance.y, 5, "The value of y should be set to 5")
1567-
self.assertEqual(z_instance.z, 0, "The default value of z should be 0")
1566+
self.assertTrue(is_dataclass(z_instance), "z_instance should be a dataclass because it is an instance of Z")
15681567

15691568
def test_helper_fields_with_class_instance(self):
15701569
# Check that we can call fields() on either a class or instance,

0 commit comments

Comments
 (0)
0