34
34
STRING_WITH_FORMAT_TYPES = (DateProperty , DateTimeProperty , FileProperty )
35
35
36
36
37
- def merge_properties ( # noqa:PLR0911
37
+ def merge_properties ( # noqa:PLR0911
38
38
prop1 : Property ,
39
39
prop2 : Property ,
40
40
parent_name : str ,
@@ -83,7 +83,9 @@ def merge_properties( # noqa:PLR0911
83
83
)
84
84
85
85
86
- def _merge_same_type (prop1 : Property , prop2 : Property , parent_name : str , config : Config ) -> Property | None | PropertyError :
86
+ def _merge_same_type (
87
+ prop1 : Property , prop2 : Property , parent_name : str , config : Config
88
+ ) -> Property | None | PropertyError :
87
89
if type (prop1 ) is not type (prop2 ):
88
90
return None
89
91
@@ -105,7 +107,9 @@ def _merge_same_type(prop1: Property, prop2: Property, parent_name: str, config:
105
107
return _merge_common_attributes (prop1 , prop2 )
106
108
107
109
108
- def _merge_models (prop1 : ModelProperty , prop2 : ModelProperty , parent_name : str , config : Config ) -> Property | PropertyError :
110
+ def _merge_models (
111
+ prop1 : ModelProperty , prop2 : ModelProperty , parent_name : str , config : Config
112
+ ) -> Property | PropertyError :
109
113
# Ideally, we would treat this case the same as a schema that consisted of "allOf: [prop1, prop2]",
110
114
# applying the property merge logic recursively and creating a new third schema if the result could
111
115
# not be fully described by one or the other. But for now we will just handle the common case where
@@ -115,7 +119,7 @@ def _merge_models(prop1: ModelProperty, prop2: ModelProperty, parent_name: str,
115
119
if prop .needs_post_processing ():
116
120
# This means not all of the details of the schema have been filled in, possibly due to a
117
121
# forward reference. That may be resolved in a later pass, but for now we can't proceed.
118
- return PropertyError (f"Schema for { prop } in allOf was not processed" , data = prop )
122
+ return PropertyError (f"Schema for { prop } in allOf was not processed" , data = prop . data )
119
123
120
124
# Detect whether one of the schemas is derived from the other-- that is, if it is (or is equivalent
121
125
# to) the result of taking the other type and adding/modifying properties with allOf. If so, then
@@ -137,9 +141,9 @@ def _merge_models(prop1: ModelProperty, prop2: ModelProperty, parent_name: str,
137
141
merged_props [sub_prop .name ] = merged_prop
138
142
else :
139
143
merged_props [sub_prop .name ] = sub_prop
140
-
144
+
141
145
prop_data = _gather_property_data (merged_props .values (), Schemas ())
142
-
146
+
143
147
name = prop2 .name
144
148
class_string = f"{ utils .pascal_case (parent_name )} { utils .pascal_case (name )} "
145
149
class_info = Class .from_string (string = class_string , config = config )
@@ -276,7 +280,9 @@ def _values_are_subset(prop1: EnumProperty, prop2: EnumProperty) -> bool:
276
280
return set (prop1 .values .items ()) <= set (prop2 .values .items ())
277
281
278
282
279
- def _model_is_extension_of (extended_model : ModelProperty , base_model : ModelProperty , parent_name : str , config : Config ) -> bool :
283
+ def _model_is_extension_of (
284
+ extended_model : ModelProperty , base_model : ModelProperty , parent_name : str , config : Config
285
+ ) -> bool :
280
286
def _properties_are_extension_of (extended_list : list [Property ], base_list : list [Property ]) -> bool :
281
287
for p2 in base_list :
282
288
if not [p1 for p1 in extended_list if _property_is_extension_of (p2 , p1 , parent_name , config )]:
@@ -288,7 +294,9 @@ def _properties_are_extension_of(extended_list: list[Property], base_list: list[
288
294
) and _properties_are_extension_of (extended_model .optional_properties , base_model .optional_properties )
289
295
290
296
291
- def _property_is_extension_of (extended_prop : PropertyProtocol , base_prop : PropertyProtocol , parent_name : str , config : Config ) -> bool :
297
+ def _property_is_extension_of (
298
+ extended_prop : Property , base_prop : Property , parent_name : str , config : Config
299
+ ) -> bool :
292
300
return base_prop .name == extended_prop .name and (
293
301
base_prop == extended_prop or merge_properties (base_prop , extended_prop , parent_name , config ) == extended_prop
294
302
)
0 commit comments