Skip to content

Commit 49753fa

Browse files
Another style
1 parent 39ace8c commit 49753fa

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

openapi_python_client/parser/properties/model_property.py

+16-18
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,18 @@ def get_imports(self, *, prefix: str) -> Set[str]:
4848
return imports
4949

5050

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+
5163
def _merge_properties(first: Property, second: Property) -> Union[Property, PropertyError]:
5264
nullable = first.nullable and second.nullable
5365
required = first.required or second.required
@@ -58,26 +70,12 @@ def _merge_properties(first: Property, second: Property) -> Union[Property, Prop
5870
if first != second:
5971
return PropertyError(header="Cannot merge properties", detail="Properties has conflicting values")
6072
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):
7974
first = attr.evolve(first, nullable=nullable, required=required)
8075
return first
76+
elif _is_subtype(second, first):
77+
second = attr.evolve(second, nullable=nullable, required=required)
78+
return second
8179
else:
8280
return PropertyError(
8381
header="Cannot merge properties",

0 commit comments

Comments
 (0)