@@ -48,6 +48,18 @@ def get_imports(self, *, prefix: str) -> Set[str]:
48
48
return imports
49
49
50
50
51
+ def _is_subtype (first : Property , second : Property ) -> bool :
52
+ return (
53
+ first .__class__ .__name__ == "EnumProperty"
54
+ and first .value_type == str
55
+ and second .__class__ .__name__ == "StringProperty"
56
+ ) or (
57
+ first .__class__ .__name__ == "EnumProperty"
58
+ and first .value_type == int
59
+ and second .__class__ .__name__ == "IntProperty"
60
+ )
61
+
62
+
51
63
def _merge_properties (first : Property , second : Property ) -> Union [Property , PropertyError ]:
52
64
nullable = first .nullable and second .nullable
53
65
required = first .required or second .required
@@ -58,26 +70,12 @@ def _merge_properties(first: Property, second: Property) -> Union[Property, Prop
58
70
if first != second :
59
71
return PropertyError (header = "Cannot merge properties" , detail = "Properties has conflicting values" )
60
72
return first
61
- elif (
62
- first .__class__ .__name__ == "StringProperty"
63
- and second .__class__ .__name__ == "EnumProperty"
64
- and second .value_type == str
65
- or first .__class__ .__name__ == "IntProperty"
66
- and second .__class__ .__name__ == "EnumProperty"
67
- and second .value_type == int
68
- ):
69
- second = attr .evolve (second , nullable = nullable , required = required )
70
- return second
71
- elif (
72
- second .__class__ .__name__ == "StringProperty"
73
- and first .__class__ .__name__ == "EnumProperty"
74
- and first .value_type == str
75
- or second .__class__ .__name__ == "IntProperty"
76
- and first .__class__ .__name__ == "EnumProperty"
77
- and first .value_type == int
78
- ):
73
+ elif _is_subtype (first , second ):
79
74
first = attr .evolve (first , nullable = nullable , required = required )
80
75
return first
76
+ elif _is_subtype (second , first ):
77
+ second = attr .evolve (second , nullable = nullable , required = required )
78
+ return second
81
79
else :
82
80
return PropertyError (
83
81
header = "Cannot merge properties" ,
0 commit comments