Skip to content

Commit 082657c

Browse files
authored
reformatted on ruff 0.9 (#113)
1 parent 4af2abf commit 082657c

File tree

11 files changed

+53
-53
lines changed

11 files changed

+53
-53
lines changed

RATapi/classlist.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def __str__(self):
6868
[
6969
[index]
7070
+ list(
71-
f"{'Data array: ['+' x '.join(str(i) for i in v.shape) if v.size > 0 else '['}]"
71+
f"{'Data array: [' + ' x '.join(str(i) for i in v.shape) if v.size > 0 else '['}]"
7272
if isinstance(v, np.ndarray)
7373
else "\n".join(element for element in v)
7474
if k == "model"
@@ -364,7 +364,7 @@ def _check_unique_name_fields(self, input_list: Sequence[T]) -> None:
364364
if new_indices:
365365
new_list = ", ".join(str(i) for i in new_indices[:-1])
366366
new_string = (
367-
f" item{f's {new_list} and ' if new_list else ' '}" f"{new_indices[-1]} of the input list"
367+
f" item{f's {new_list} and ' if new_list else ' '}{new_indices[-1]} of the input list"
368368
)
369369
error_list.append(
370370
f" '{name}' is shared between{existing_string}"

RATapi/controls.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ def warn_setting_incorrect_properties(self, handler: ValidatorFunctionWrapHandle
9292
procedure = input_dict.get("procedure", Procedures.Calculate)
9393
custom_error_msgs = {
9494
"extra_forbidden": f'Extra inputs are not permitted. The fields for the "{procedure}"'
95-
f' controls procedure are:\n '
96-
f'{", ".join(fields.get("procedure", []))}\n',
95+
f" controls procedure are:\n "
96+
f"{', '.join(fields.get('procedure', []))}\n",
9797
}
9898
custom_error_list = custom_pydantic_validation_error(exc.errors(), custom_error_msgs)
9999
raise ValidationError.from_exception_data(exc.title, custom_error_list, hide_input=True) from None
@@ -116,7 +116,7 @@ def warn_setting_incorrect_properties(self, handler: ValidatorFunctionWrapHandle
116116
f'\nThe current controls procedure is "{new_procedure}", but the property'
117117
f' "{field}" applies instead to the {", ".join(incorrect_procedures)} procedure.\n\n'
118118
f' The fields for the "{new_procedure}" controls procedure are:\n'
119-
f' {", ".join(fields[new_procedure])}\n',
119+
f" {', '.join(fields[new_procedure])}\n",
120120
stacklevel=2,
121121
)
122122

RATapi/examples/languages/run_custom_file_languages.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
start = time.time()
1818
project, results = RAT.run(project, controls)
1919
end = time.time()
20-
print(f"Python time is: {end-start}s\n")
20+
print(f"Python time is: {end - start}s\n")
2121

2222
RAT.plotting.plot_ref_sld(project, results)
2323

@@ -27,7 +27,7 @@
2727
start = time.time()
2828
project, results = RAT.run(project, controls)
2929
end = time.time()
30-
print(f"Matlab time is: {end-start}s\n")
30+
print(f"Matlab time is: {end - start}s\n")
3131

3232
RAT.plotting.plot_ref_sld(project, results)
3333

@@ -37,6 +37,6 @@
3737
start = time.time()
3838
project, results = RAT.run(project, controls)
3939
end = time.time()
40-
print(f"C++ time is: {end-start}s\n")
40+
print(f"C++ time is: {end - start}s\n")
4141

4242
RAT.plotting.plot_ref_sld(project, results)

RATapi/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ def __eq__(self, other: object) -> bool:
274274
def __str__(self):
275275
table = prettytable.PrettyTable()
276276
table.field_names = [key.replace("_", " ") for key in self.__dict__]
277-
array_entry = f"{'Data array: ['+' x '.join(str(i) for i in self.data.shape) if self.data.size > 0 else '['}]"
277+
array_entry = f"{'Data array: [' + ' x '.join(str(i) for i in self.data.shape) if self.data.size > 0 else '['}]"
278278
table.add_row([self.name, array_entry, self.data_range, self.simulation_range])
279279
return table.get_string()
280280

RATapi/project.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ def check_layers(cls, value: ClassList, info: ValidationInfo):
299299
if not all(isinstance(element, model) for element in value):
300300
raise ValueError(
301301
f'"The layers attribute contains {other_model}s, '
302-
f'but the absorption parameter is {info.data["absorption"]}. '
302+
f"but the absorption parameter is {info.data['absorption']}. "
303303
f'The attribute should be a ClassList of {model_name} instead."'
304304
)
305305

@@ -568,15 +568,15 @@ def check_protected_parameters(self) -> "Project":
568568
removed_params = [
569569
param for param in self._protected_parameters[class_list] if param not in protected_parameters
570570
]
571-
raise ValueError(f'Can\'t delete the protected parameters: {", ".join(str(i) for i in removed_params)}')
571+
raise ValueError(f"Can't delete the protected parameters: {', '.join(str(i) for i in removed_params)}")
572572
self._protected_parameters = self.get_all_protected_parameters()
573573
return self
574574

575575
def __str__(self):
576576
output = ""
577577
for key, value in self.__dict__.items():
578578
if value:
579-
output += f'{key.replace("_", " ").title() + ": " :-<100}\n\n'
579+
output += f"{key.replace('_', ' ').title() + ': ':-<100}\n\n"
580580
try:
581581
output += value.value + "\n\n" # For enums
582582
except AttributeError:

RATapi/run.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def run(project, controls):
120120
end = time.time()
121121

122122
if display_on:
123-
print(f"Elapsed time is {end-start:.3f} seconds\n")
123+
print(f"Elapsed time is {end - start:.3f} seconds\n")
124124

125125
results = make_results(controls.procedure, output_results, bayes_results)
126126

RATapi/utils/plotting.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def plot_ref_sld_helper(
138138

139139
# Plot the slds on plot (1,2)
140140
for j in range(len(sld)):
141-
label = name if len(sld) == 1 else f"{name} Domain {j+1}"
141+
label = name if len(sld) == 1 else f"{name} Domain {j + 1}"
142142
sld_plot.plot(sld[j][:, 0], sld[j][:, 1], label=label, linewidth=1)
143143

144144
# Plot confidence intervals if required

tests/test_controls.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,9 @@ def test_initialise_non_calculate_properties(self, wrong_property: str, value: A
132132
UserWarning,
133133
match=f'\nThe current controls procedure is "calculate", but the property'
134134
f' "{wrong_property}" applies instead to the'
135-
f' {", ".join(incorrect_procedures)} procedure.\n\n'
135+
f" {', '.join(incorrect_procedures)} procedure.\n\n"
136136
f' The fields for the "calculate" controls procedure are:\n'
137-
f' {", ".join(fields["calculate"])}\n',
137+
f" {', '.join(fields['calculate'])}\n",
138138
):
139139
Controls(procedure=Procedures.Calculate, **{wrong_property: value})
140140

@@ -171,9 +171,9 @@ def test_set_non_calculate_properties(self, wrong_property: str, value: Any) ->
171171
UserWarning,
172172
match=f'\nThe current controls procedure is "calculate", but the property'
173173
f' "{wrong_property}" applies instead to the'
174-
f' {", ".join(incorrect_procedures)} procedure.\n\n'
174+
f" {', '.join(incorrect_procedures)} procedure.\n\n"
175175
f' The fields for the "calculate" controls procedure are:\n'
176-
f' {", ".join(fields["calculate"])}\n',
176+
f" {', '.join(fields['calculate'])}\n",
177177
):
178178
setattr(self.calculate, wrong_property, value)
179179

@@ -301,9 +301,9 @@ def test_initialise_non_simplex_properties(self, wrong_property: str, value: Any
301301
UserWarning,
302302
match=f'\nThe current controls procedure is "simplex", but the property'
303303
f' "{wrong_property}" applies instead to the'
304-
f' {", ".join(incorrect_procedures)} procedure.\n\n'
304+
f" {', '.join(incorrect_procedures)} procedure.\n\n"
305305
f' The fields for the "simplex" controls procedure are:\n'
306-
f' {", ".join(fields["simplex"])}\n',
306+
f" {', '.join(fields['simplex'])}\n",
307307
):
308308
Controls(procedure=Procedures.Simplex, **{wrong_property: value})
309309

@@ -334,9 +334,9 @@ def test_set_non_simplex_properties(self, wrong_property: str, value: Any) -> No
334334
UserWarning,
335335
match=f'\nThe current controls procedure is "simplex", but the property'
336336
f' "{wrong_property}" applies instead to the'
337-
f' {", ".join(incorrect_procedures)} procedure.\n\n'
337+
f" {', '.join(incorrect_procedures)} procedure.\n\n"
338338
f' The fields for the "simplex" controls procedure are:\n'
339-
f' {", ".join(fields["simplex"])}\n',
339+
f" {', '.join(fields['simplex'])}\n",
340340
):
341341
setattr(self.simplex, wrong_property, value)
342342

@@ -458,9 +458,9 @@ def test_initialise_non_de_properties(self, wrong_property: str, value: Any) ->
458458
UserWarning,
459459
match=f'\nThe current controls procedure is "de", but the property'
460460
f' "{wrong_property}" applies instead to the'
461-
f' {", ".join(incorrect_procedures)} procedure.\n\n'
461+
f" {', '.join(incorrect_procedures)} procedure.\n\n"
462462
f' The fields for the "de" controls procedure are:\n'
463-
f' {", ".join(fields["de"])}\n',
463+
f" {', '.join(fields['de'])}\n",
464464
):
465465
Controls(procedure=Procedures.DE, **{wrong_property: value})
466466

@@ -489,9 +489,9 @@ def test_set_non_de_properties(self, wrong_property: str, value: Any) -> None:
489489
UserWarning,
490490
match=f'\nThe current controls procedure is "de", but the property'
491491
f' "{wrong_property}" applies instead to the'
492-
f' {", ".join(incorrect_procedures)} procedure.\n\n'
492+
f" {', '.join(incorrect_procedures)} procedure.\n\n"
493493
f' The fields for the "de" controls procedure are:\n'
494-
f' {", ".join(fields["de"])}\n',
494+
f" {', '.join(fields['de'])}\n",
495495
):
496496
setattr(self.de, wrong_property, value)
497497

@@ -627,9 +627,9 @@ def test_initialise_non_ns_properties(self, wrong_property: str, value: Any) ->
627627
UserWarning,
628628
match=f'\nThe current controls procedure is "ns", but the property'
629629
f' "{wrong_property}" applies instead to the'
630-
f' {", ".join(incorrect_procedures)} procedure.\n\n'
630+
f" {', '.join(incorrect_procedures)} procedure.\n\n"
631631
f' The fields for the "ns" controls procedure are:\n'
632-
f' {", ".join(fields["ns"])}\n',
632+
f" {', '.join(fields['ns'])}\n",
633633
):
634634
Controls(procedure=Procedures.NS, **{wrong_property: value})
635635

@@ -662,9 +662,9 @@ def test_set_non_ns_properties(self, wrong_property: str, value: Any) -> None:
662662
UserWarning,
663663
match=f'\nThe current controls procedure is "ns", but the property'
664664
f' "{wrong_property}" applies instead to the'
665-
f' {", ".join(incorrect_procedures)} procedure.\n\n'
665+
f" {', '.join(incorrect_procedures)} procedure.\n\n"
666666
f' The fields for the "ns" controls procedure are:\n'
667-
f' {", ".join(fields["ns"])}\n',
667+
f" {', '.join(fields['ns'])}\n",
668668
):
669669
setattr(self.ns, wrong_property, value)
670670

@@ -797,9 +797,9 @@ def test_initialise_non_dream_properties(self, wrong_property: str, value: Any)
797797
UserWarning,
798798
match=f'\nThe current controls procedure is "dream", but the property'
799799
f' "{wrong_property}" applies instead to the'
800-
f' {", ".join(incorrect_procedures)} procedure.\n\n'
800+
f" {', '.join(incorrect_procedures)} procedure.\n\n"
801801
f' The fields for the "dream" controls procedure are:\n'
802-
f' {", ".join(fields["dream"])}\n',
802+
f" {', '.join(fields['dream'])}\n",
803803
):
804804
Controls(procedure=Procedures.DREAM, **{wrong_property: value})
805805

@@ -830,9 +830,9 @@ def test_set_non_dream_properties(self, wrong_property: str, value: Any) -> None
830830
UserWarning,
831831
match=f'\nThe current controls procedure is "dream", but the property'
832832
f' "{wrong_property}" applies instead to the'
833-
f' {", ".join(incorrect_procedures)} procedure.\n\n'
833+
f" {', '.join(incorrect_procedures)} procedure.\n\n"
834834
f' The fields for the "dream" controls procedure are:\n'
835-
f' {", ".join(fields["dream"])}\n',
835+
f" {', '.join(fields['dream'])}\n",
836836
):
837837
setattr(self.dream, wrong_property, value)
838838

tests/test_convert.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ def dspc_bilayer():
3333
param = project.background_parameters[i]
3434
for background in project.backgrounds:
3535
if background.value_1 == param.name:
36-
background.value_1 = f"Background parameter {i+1}"
37-
param.name = f"Background parameter {i+1}"
36+
background.value_1 = f"Background parameter {i + 1}"
37+
param.name = f"Background parameter {i + 1}"
3838

3939
for i in range(0, len(project.resolution_parameters)):
4040
param = project.resolution_parameters[i]
4141
for resolution in project.resolutions:
4242
if resolution.value_1 == param.name:
43-
resolution.value_1 = f"Resolution parameter {i+1}"
44-
param.name = f"Resolution parameter {i+1}"
43+
resolution.value_1 = f"Resolution parameter {i + 1}"
44+
param.name = f"Resolution parameter {i + 1}"
4545

4646
return project
4747

tests/test_models.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def test_initialise_with_wrong_type(self, model: Callable, model_params: dict) -
7070
"""When initialising a model with the wrong type for the "name" field, we should raise a ValidationError."""
7171
with pytest.raises(
7272
pydantic.ValidationError,
73-
match=f"1 validation error for {model.__name__}\nname\n " f"Input should be a valid string",
73+
match=f"1 validation error for {model.__name__}\nname\n Input should be a valid string",
7474
):
7575
model(name=1, **model_params)
7676

@@ -79,23 +79,23 @@ def test_assignment_with_wrong_type(self, model: Callable, model_params: dict) -
7979
test_model = model(**model_params)
8080
with pytest.raises(
8181
pydantic.ValidationError,
82-
match=f"1 validation error for {model.__name__}\nname\n " f"Input should be a valid string",
82+
match=f"1 validation error for {model.__name__}\nname\n Input should be a valid string",
8383
):
8484
test_model.name = 1
8585

8686
def test_initialise_with_zero_length_name(self, model: Callable, model_params: dict) -> None:
8787
"""When initialising a model with a zero length name, we should raise a ValidationError."""
8888
with pytest.raises(
8989
pydantic.ValidationError,
90-
match=f"1 validation error for {model.__name__}\nname\n " f"String should have at least 1 character",
90+
match=f"1 validation error for {model.__name__}\nname\n String should have at least 1 character",
9191
):
9292
model(name="", **model_params)
9393

9494
def test_initialise_with_extra_fields(self, model: Callable, model_params: dict) -> None:
9595
"""When initialising a model with unspecified fields, we should raise a ValidationError."""
9696
with pytest.raises(
9797
pydantic.ValidationError,
98-
match=f"1 validation error for {model.__name__}\nnew_field\n " f"Extra inputs are not permitted",
98+
match=f"1 validation error for {model.__name__}\nnew_field\n Extra inputs are not permitted",
9999
):
100100
model(new_field=1, **model_params)
101101

@@ -134,7 +134,7 @@ def test_data_too_few_dimensions(input_data: np.ndarray[float]) -> None:
134134
"""
135135
with pytest.raises(
136136
pydantic.ValidationError,
137-
match='1 validation error for Data\ndata\n Value error, "data" must ' "have at least two dimensions",
137+
match='1 validation error for Data\ndata\n Value error, "data" must have at least two dimensions',
138138
):
139139
RATapi.models.Data(data=input_data)
140140

@@ -153,7 +153,7 @@ def test_data_too_few_values(input_data: np.ndarray[float]) -> None:
153153
"""
154154
with pytest.raises(
155155
pydantic.ValidationError,
156-
match='1 validation error for Data\ndata\n Value error, "data" must ' "have at least three columns",
156+
match='1 validation error for Data\ndata\n Value error, "data" must have at least three columns',
157157
):
158158
RATapi.models.Data(data=input_data)
159159

@@ -184,9 +184,9 @@ def test_two_values_in_data_range(input_range: list[float]) -> None:
184184
"""
185185
with pytest.raises(
186186
pydantic.ValidationError,
187-
match=f'1 validation error for Data\ndata_range\n List should have '
188-
f'at {"least" if len(input_range) < 2 else "most"} 2 items '
189-
f'after validation, not {len(input_range)}',
187+
match=f"1 validation error for Data\ndata_range\n List should have "
188+
f"at {'least' if len(input_range) < 2 else 'most'} 2 items "
189+
f"after validation, not {len(input_range)}",
190190
):
191191
RATapi.models.Data(data_range=input_range)
192192

@@ -205,9 +205,9 @@ def test_two_values_in_simulation_range(input_range: list[float]) -> None:
205205
"""
206206
with pytest.raises(
207207
pydantic.ValidationError,
208-
match=f'1 validation error for Data\nsimulation_range\n List should '
209-
f'have at {"least" if len(input_range) < 2 else "most"} 2 items '
210-
f'after validation, not {len(input_range)}',
208+
match=f"1 validation error for Data\nsimulation_range\n List should "
209+
f"have at {'least' if len(input_range) < 2 else 'most'} 2 items "
210+
f"after validation, not {len(input_range)}",
211211
):
212212
RATapi.models.Data(simulation_range=input_range)
213213

0 commit comments

Comments
 (0)