Skip to content

Commit d39f43c

Browse files
add RUF check and fixes
Signed-off-by: Laurynas Jagutis <[email protected]>
1 parent 41c4286 commit d39f43c

File tree

10 files changed

+18
-17
lines changed

10 files changed

+18
-17
lines changed

code_generation/code_gen.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def render_attribute_classes(self, template_path: Path, data_path: Path, output_
7575
attribute_class.attributes = new_attribute_list
7676
# get full attribute
7777
if attribute_class.base is not None:
78-
base_class = list(filter(lambda x: x.name == attribute_class.base, dataset_meta_data.classes))[0]
78+
base_class = next(filter(lambda x: x.name == attribute_class.base, dataset_meta_data.classes))
7979
attribute_class.full_attributes = base_class.full_attributes + attribute_class.attributes
8080
attribute_class.base_attributes = base_class.base_attributes.copy()
8181
attribute_class.base_attributes[base_class.name] = base_class.full_attributes

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@ select = [
125125
"PIE",
126126
"SLF",
127127
"UP",
128-
"RSE"
128+
"RSE",
129+
"RUF"
129130
]
130131
# the rule is deprecated, https://docs.astral.sh/ruff/rules/non-pep604-isinstance/#deprecation
131132
ignore = ["UP038"]

src/power_grid_model/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@
3030
from power_grid_model.typing import ComponentAttributeMapping
3131

3232
__all__ = [
33-
"attribute_dtype",
34-
"attribute_empty_value",
3533
"AngleMeasurementType",
3634
"Branch3Side",
3735
"BranchSide",
@@ -43,12 +41,14 @@
4341
"DatasetType",
4442
"FaultPhase",
4543
"FaultType",
46-
"initialize_array",
4744
"LoadGenType",
4845
"MeasuredTerminalType",
4946
"PowerGridModel",
50-
"power_grid_meta_data",
5147
"ShortCircuitVoltageScaling",
5248
"TapChangingStrategy",
5349
"WindingType",
50+
"attribute_dtype",
51+
"attribute_empty_value",
52+
"initialize_array",
53+
"power_grid_meta_data",
5454
]

src/power_grid_model/_core/power_grid_core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ def make_c_binding(func: Callable):
184184
if is_destroy_func:
185185
getattr(_CDLL, f"PGM_{name}").argtypes = c_argtypes
186186
else:
187-
getattr(_CDLL, f"PGM_{name}").argtypes = [HandlePtr] + c_argtypes
187+
getattr(_CDLL, f"PGM_{name}").argtypes = [HandlePtr, *c_argtypes]
188188
getattr(_CDLL, f"PGM_{name}").restype = c_restype
189189

190190
# binding function

src/power_grid_model/data_types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
# Import non class symbols as private to reassign and provide a docstring.
1313
# Not necessary for class, as sphinx autodoc finds their docstrings
14-
from power_grid_model._core.data_types import ( # noqa: F401, I001
14+
from power_grid_model._core.data_types import ( # noqa: F401
1515
AsymValue as _AsymValue,
1616
AttributeType as _AttributeType,
1717
AttributeValue as _AttributeValue,

src/power_grid_model/typing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
DatasetMetaData,
2020
PowerGridMetaData,
2121
)
22-
from power_grid_model._core.typing import ( # noqa: F401
22+
from power_grid_model._core.typing import (
2323
ComponentAttributeMapping as _ComponentAttributeMapping,
2424
)
2525
from power_grid_model.enum import ComponentAttributeFilterOptions # noqa: F401

src/power_grid_model/validation/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
from power_grid_model.validation.utils import errors_to_string
1515

1616
__all__ = [
17+
"ValidationError",
18+
"ValidationException",
1719
"assert_valid_batch_data",
1820
"assert_valid_data_structure",
1921
"assert_valid_input_data",
2022
"errors_to_string",
2123
"validate_batch_data",
2224
"validate_input_data",
23-
"ValidationError",
24-
"ValidationException",
2525
]

src/power_grid_model/validation/_rules.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1166,7 +1166,7 @@ def any_voltage_angle_measurement_if_global_current_measurement(
11661166

11671167
return [
11681168
MissingVoltageAngleMeasurementError(
1169-
fields=[(component, angle_measurement_type_field)] + list(voltage_sensor_u_angle_measured.items()),
1169+
fields=[(component, angle_measurement_type_field), *list(voltage_sensor_u_angle_measured.items())],
11701170
ids=[
11711171
(sensor_type, id_)
11721172
for sensor_type, sensor_data in voltage_and_current_sensor_ids.items()

tests/unit/test_data_handling.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ def columnar_array(component_type, n_components, attributes=None, batch_size_tup
2323
set(component_dtype.names) & set(attributes) if attributes is not None else component_dtype.names
2424
)
2525
return {
26-
attr: np.empty((n_components,) + batch_size_tuple, dtype=component_dtype[attr]) for attr in required_attributes
26+
attr: np.empty((n_components, *batch_size_tuple), dtype=component_dtype[attr]) for attr in required_attributes
2727
}
2828

2929

3030
def row_array(component_type, n_components, batch_size_tuple=()):
31-
return initialize_array(DT.sym_output, component_type, (n_components,) + batch_size_tuple)
31+
return initialize_array(DT.sym_output, component_type, (n_components, *batch_size_tuple))
3232

3333

3434
@pytest.fixture(params=[1, 15])

tests/unit/validation/test_input_validation.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ def original_data() -> dict[ComponentType, np.ndarray]:
365365
asym_current_sensor["angle_measurement_type"] = [0, 1, 10, 2, 0]
366366

367367
fault = initialize_array(DatasetType.input, ComponentType.fault, 20)
368-
fault["id"] = [1] + list(range(32, 51))
368+
fault["id"] = [1, *list(range(32, 51))]
369369
fault["status"] = [0, -1, 2] + 17 * [1]
370370
fault["fault_type"] = 6 * [0] + 4 * [1] + 4 * [2] + 4 * [3] + [_nan_type(ComponentType.fault, "fault_type"), 4]
371371
fault["fault_phase"] = (
@@ -763,7 +763,7 @@ def test_validate_input_data_sym_calculation(input_data):
763763

764764
assert NotBooleanError(ComponentType.fault, "status", [32, 33]) in validation_errors
765765
assert (
766-
InvalidIdError(ComponentType.fault, "fault_object", [1] + list(range(32, 42)), [ComponentType.node])
766+
InvalidIdError(ComponentType.fault, "fault_object", [1, *list(range(32, 42))], [ComponentType.node])
767767
in validation_errors
768768
)
769769

@@ -955,7 +955,7 @@ def test_fault(input_data):
955955
assert validation_errors is not None
956956
assert InvalidEnumValueError(ComponentType.fault, "fault_type", [50], FaultType) in validation_errors
957957
assert InvalidEnumValueError(ComponentType.fault, "fault_phase", [50], FaultPhase) in validation_errors
958-
assert FaultPhaseError(ComponentType.fault, ["fault_type", "fault_phase"], [1] + list(range(32, 51)))
958+
assert FaultPhaseError(ComponentType.fault, ["fault_type", "fault_phase"], [1, *list(range(32, 51))])
959959
assert NotGreaterOrEqualError(ComponentType.fault, "r_f", [1], 0) in validation_errors
960960
assert (
961961
NotIdenticalError(

0 commit comments

Comments
 (0)