Skip to content

Commit e6cdf95

Browse files
committed
lint
1 parent e35b31a commit e6cdf95

File tree

4 files changed

+24
-13
lines changed

4 files changed

+24
-13
lines changed

openapi_python_client/parser/properties/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def _property_from_ref(
137137
return prop, schemas
138138

139139

140-
def property_from_data( # noqa: PLR0911
140+
def property_from_data( # noqa: PLR0911, PLR0912
141141
name: str,
142142
required: bool,
143143
data: oai.Reference | oai.Schema,

openapi_python_client/parser/properties/merge_properties.py

+16-8
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
STRING_WITH_FORMAT_TYPES = (DateProperty, DateTimeProperty, FileProperty)
3535

3636

37-
def merge_properties( # noqa:PLR0911
37+
def merge_properties( # noqa:PLR0911
3838
prop1: Property,
3939
prop2: Property,
4040
parent_name: str,
@@ -83,7 +83,9 @@ def merge_properties( # noqa:PLR0911
8383
)
8484

8585

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:
8789
if type(prop1) is not type(prop2):
8890
return None
8991

@@ -105,7 +107,9 @@ def _merge_same_type(prop1: Property, prop2: Property, parent_name: str, config:
105107
return _merge_common_attributes(prop1, prop2)
106108

107109

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:
109113
# Ideally, we would treat this case the same as a schema that consisted of "allOf: [prop1, prop2]",
110114
# applying the property merge logic recursively and creating a new third schema if the result could
111115
# 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,
115119
if prop.needs_post_processing():
116120
# This means not all of the details of the schema have been filled in, possibly due to a
117121
# 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)
119123

120124
# Detect whether one of the schemas is derived from the other-- that is, if it is (or is equivalent
121125
# 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,
137141
merged_props[sub_prop.name] = merged_prop
138142
else:
139143
merged_props[sub_prop.name] = sub_prop
140-
144+
141145
prop_data = _gather_property_data(merged_props.values(), Schemas())
142-
146+
143147
name = prop2.name
144148
class_string = f"{utils.pascal_case(parent_name)}{utils.pascal_case(name)}"
145149
class_info = Class.from_string(string=class_string, config=config)
@@ -276,7 +280,9 @@ def _values_are_subset(prop1: EnumProperty, prop2: EnumProperty) -> bool:
276280
return set(prop1.values.items()) <= set(prop2.values.items())
277281

278282

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:
280286
def _properties_are_extension_of(extended_list: list[Property], base_list: list[Property]) -> bool:
281287
for p2 in base_list:
282288
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[
288294
) and _properties_are_extension_of(extended_model.optional_properties, base_model.optional_properties)
289295

290296

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:
292300
return base_prop.name == extended_prop.name and (
293301
base_prop == extended_prop or merge_properties(base_prop, extended_prop, parent_name, config) == extended_prop
294302
)

openapi_python_client/parser/properties/model_property.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,8 @@ def _add_if_no_conflict(new_prop: Property) -> PropertyError | None:
342342

343343

344344
def _gather_property_data(properties: Iterable[Property], schemas: Schemas) -> _PropertyData:
345-
required_properties = []
346-
optional_properties = []
345+
required_properties: list[Property] = []
346+
optional_properties: list[Property] = []
347347
relative_imports: set[str] = set()
348348
lazy_imports: set[str] = set()
349349
for prop in properties:

tests/test_parser/test_properties/test_merge_properties.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,8 @@ def test_merge_enums(literal_enums, enum_property_factory, literal_enum_property
153153

154154
@pytest.mark.parametrize("literal_enums", (False, True))
155155
def test_merge_string_with_string_enum(
156-
literal_enums, string_property_factory, enum_property_factory, literal_enum_property_factory, config):
156+
literal_enums, string_property_factory, enum_property_factory, literal_enum_property_factory, config
157+
):
157158
string_prop = string_property_factory(default=Value("A", "A"), description="desc1", example="example1")
158159
enum_prop = (
159160
literal_enum_property_factory(
@@ -327,7 +328,9 @@ def test_merge_related_models(model_property_factory, string_property_factory, c
327328
class_info=Class.from_string(string="DerivedModel", config=config),
328329
)
329330

330-
assert merge_properties(base_model, extension_model, "", config) == evolve(extension_model, example=base_model.example)
331+
assert merge_properties(base_model, extension_model, "", config) == evolve(
332+
extension_model, example=base_model.example
333+
)
331334
assert merge_properties(extension_model, base_model, "", config) == evolve(
332335
extension_model, description=base_model.description, example=base_model.example
333336
)

0 commit comments

Comments
 (0)