File tree Expand file tree Collapse file tree 2 files changed +7
-9
lines changed
Lib/test/test_dataclasses Expand file tree Collapse file tree 2 files changed +7
-9
lines changed Original file line number Diff line number Diff line change @@ -461,9 +461,8 @@ Module contents
461
461
462
462
.. function :: is_dataclass(obj)
463
463
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 ``.
467
466
468
467
If you need to know if a class is an instance of a dataclass (and
469
468
not a dataclass itself), then add a further check for ``not
Original file line number Diff line number Diff line change @@ -1555,16 +1555,15 @@ class X:
1555
1555
y : int
1556
1556
1557
1557
class Z (X ):
1558
- z : int = 0 # Adding a default field to demonstrate inheritance and dataclass behavior
1558
+ pass
1559
1559
1560
- # Check if X is a dataclass
1560
+ # Assert that both X and Z are recognized as dataclasses
1561
1561
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
1563
1562
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
1565
1565
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" )
1568
1567
1569
1568
def test_helper_fields_with_class_instance (self ):
1570
1569
# Check that we can call fields() on either a class or instance,
You can’t perform that action at this time.
0 commit comments