-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make dataclasses/attrs comparison recursive, fixes #4675
- Loading branch information
ibriquem
committed
Feb 28, 2020
1 parent
f77d606
commit a55bd1c
Showing
4 changed files
with
66 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Make dataclasses/attrs comparison recursive. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
testing/example_scripts/dataclasses/test_compare_recursive_dataclasses.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from dataclasses import dataclass | ||
from dataclasses import field | ||
|
||
|
||
@dataclass | ||
class SimpleDataObject: | ||
field_a: int = field() | ||
field_b: int = field() | ||
|
||
|
||
@dataclass | ||
class ComplexDataObject: | ||
field_a: SimpleDataObject = field() | ||
field_b: SimpleDataObject = field() | ||
|
||
|
||
def test_recursive_dataclasses(): | ||
|
||
left = ComplexDataObject(SimpleDataObject(1, "b"), SimpleDataObject(2, "c"),) | ||
right = ComplexDataObject(SimpleDataObject(1, "b"), SimpleDataObject(3, "c"),) | ||
|
||
assert left == right |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters