@@ -48,34 +48,43 @@ def get_imports(self, *, prefix: str) -> Set[str]:
48
48
return imports
49
49
50
50
51
+ def _is_string_enum (prop : Property ) -> bool :
52
+ return prop .__class__ .__name__ == "EnumProperty" and prop .value_type == str
53
+
54
+
55
+ def _is_int_enum (prop : Property ) -> bool :
56
+ return prop .__class__ .__name__ == "EnumProperty" and prop .value_type == int
57
+
58
+
51
59
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
+ return any (
61
+ [
62
+ _is_string_enum (first ) and second .__class__ .__name__ == "StringProperty" ,
63
+ _is_int_enum (first ) and second .__class__ .__name__ == "IntProperty" ,
64
+ _is_string_enum (first )
65
+ and _is_string_enum (second )
66
+ and set (first .values .items ()) <= set (second .values .items ()),
67
+ _is_int_enum (first ) and _is_int_enum (second ) and set (first .values .items ()) <= set (second .values .items ()),
68
+ ]
60
69
)
61
70
62
71
63
72
def _merge_properties (first : Property , second : Property ) -> Union [Property , PropertyError ]:
64
73
nullable = first .nullable and second .nullable
65
74
required = first .required or second .required
66
75
67
- if first .__class__ == second .__class__ :
68
- first = attr .evolve (first , nullable = nullable , required = required )
69
- second = attr .evolve (second , nullable = nullable , required = required )
70
- if first != second :
71
- return PropertyError (header = "Cannot merge properties" , detail = "Properties has conflicting values" )
72
- return first
73
- elif _is_subtype (first , second ):
76
+ if _is_subtype (first , second ):
74
77
first = attr .evolve (first , nullable = nullable , required = required )
75
78
return first
76
79
elif _is_subtype (second , first ):
77
80
second = attr .evolve (second , nullable = nullable , required = required )
78
81
return second
82
+ elif first .__class__ == second .__class__ :
83
+ first = attr .evolve (first , nullable = nullable , required = required )
84
+ second = attr .evolve (second , nullable = nullable , required = required )
85
+ if first != second :
86
+ return PropertyError (header = "Cannot merge properties" , detail = "Properties has conflicting values" )
87
+ return first
79
88
else :
80
89
return PropertyError (
81
90
header = "Cannot merge properties" ,
0 commit comments