File tree Expand file tree Collapse file tree 2 files changed +59
-0
lines changed Expand file tree Collapse file tree 2 files changed +59
-0
lines changed Original file line number Diff line number Diff line change @@ -6,8 +6,13 @@ def main():
6
6
d1_1 = {"a" : 1 }
7
7
d2 = {"l" : [1 , 2 , 3 ]}
8
8
d2_1 = {"l" : [1 , 2 , 3 ]}
9
+ d3 = {"d" : {"i" : 1 }}
10
+ d3_1 = {"d" : {"i" : 1 }}
11
+ d3_2 = {"d" : {"i" : 1 }, "i" : 2 }
9
12
print (d1 == d1_1 )
10
13
print (d2 == d2_1 )
14
+ print (d3 == d3_1 )
15
+ print (d3 == d3_2 )
11
16
12
17
13
18
if __name__ == '__main__' :
Original file line number Diff line number Diff line change
1
+ from typing import List
2
+ from pydantic import BaseModel
3
+
4
+
5
+ class Foo (BaseModel ):
6
+ foo_a : int
7
+ foo_b : int
8
+
9
+
10
+ class Bar (BaseModel ):
11
+ foo : Foo
12
+ bar_a : int
13
+
14
+
15
+ def compare_two_model_obj (obj_a , obj_b ):
16
+ return obj_a .dict () == obj_b .dict ()
17
+
18
+
19
+ def main ():
20
+ a = Bar (** {
21
+ 'foo' : {
22
+ 'foo_a' : 1 ,
23
+ 'foo_b' : 2 ,
24
+ },
25
+ 'bar_a' : 3 ,
26
+ })
27
+ b = Bar (** {
28
+ 'foo' : {
29
+ 'foo_a' : 1 ,
30
+ 'foo_b' : 2 ,
31
+ },
32
+ 'bar_a' : 3 ,
33
+ })
34
+ c = Bar (** {
35
+ 'foo' : {
36
+ 'foo_a' : 11 ,
37
+ 'foo_b' : 2 ,
38
+ },
39
+ 'bar_a' : 3 ,
40
+ })
41
+ d = Bar (** {
42
+ 'foo' : {
43
+ 'foo_a' : 1 ,
44
+ 'foo_b' : 2 ,
45
+ },
46
+ 'bar_a' : 31 ,
47
+ })
48
+ print ('a == b ? {}' .format (compare_two_model_obj (a , b )))
49
+ print ('a == c ? {}' .format (compare_two_model_obj (a , c )))
50
+ print ('a == d ? {}' .format (compare_two_model_obj (a , d )))
51
+
52
+
53
+ if __name__ == '__main__' :
54
+ main ()
You can’t perform that action at this time.
0 commit comments