Skip to content

Commit c4598ed

Browse files
authored
Merge pull request #1065 from PowerGridModel/feature/even-more-ruff-checks
Linting and Formatting: UP and RSE checks
2 parents dfcc11f + 5c9cfe5 commit c4598ed

22 files changed

+55
-43
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ repos:
99
- id: reuse
1010
- repo: https://github.com/astral-sh/ruff-pre-commit
1111
# Ruff version.
12-
rev: v0.12.0
12+
rev: v0.12.7
1313
hooks:
1414
# Run the linter.
1515
- id: ruff-check

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

code_generation/templates/src/power_grid_model/_core/dataset_class_maps.py.jinja

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
{%- set dataset_types = all_map.keys() %}
1010
{%- set components = all_map['input'].keys() %}
1111

12+
from collections.abc import Mapping
1213
from enum import Enum, EnumMeta
13-
from typing import Any, Mapping, TypeAlias, TypeVar
14+
from typing import Any, TypeAlias, TypeVar
1415

1516
# fmt: off
1617

pyproject.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,13 @@ select = [
142142
"ARG",
143143
"RET",
144144
"PIE",
145-
"SLF"
145+
"SLF",
146+
"UP",
147+
"RSE",
148+
"RUF"
146149
]
150+
# the rule is deprecated, https://docs.astral.sh/ruff/rules/non-pep604-isinstance/#deprecation
151+
ignore = ["UP038"]
147152

148153
[tool.ruff.lint.isort]
149154
# Imports that are imported using keyword "as" and are from the same source - are combined.

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/data_handling.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def get_output_type(*, calculation_type: CalculationType, symmetric: bool) -> Da
3838
if calculation_type == CalculationType.short_circuit:
3939
return DatasetType.sc_output
4040

41-
raise NotImplementedError()
41+
raise NotImplementedError
4242

4343

4444
def prepare_input_view(input_data: SingleDataset) -> CConstDataset:

src/power_grid_model/_core/dataset_definitions.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66

77
# This file is automatically generated. DO NOT modify it manually!
88

9+
from collections.abc import Mapping
910
from enum import Enum, EnumMeta
10-
from typing import Any, Mapping, TypeAlias, TypeVar
11+
from typing import Any, TypeAlias, TypeVar
1112

1213
# fmt: off
1314

src/power_grid_model/_core/options.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
Option class
77
"""
88

9-
from typing import Any, Callable
9+
from collections.abc import Callable
10+
from typing import Any
1011

1112
from power_grid_model._core.power_grid_core import OptionsPtr, power_grid_core as pgc
1213

src/power_grid_model/_core/power_grid_core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
Loader for the dynamic library
77
"""
88

9+
from collections.abc import Callable
910
from ctypes import CDLL, POINTER, c_char, c_char_p, c_double, c_size_t, c_void_p
1011
from inspect import signature
1112
from itertools import chain
12-
from typing import Callable
1313

1414
from power_grid_model._core.index_integer import IdC, IdxC
1515
from power_grid_model._core.power_grid_model_c.get_pgm_dll_path import get_pgm_dll_path
@@ -166,7 +166,7 @@ def make_c_binding(func: Callable):
166166
if is_destroy_func:
167167
getattr(_CDLL, f"PGM_{name}").argtypes = c_argtypes
168168
else:
169-
getattr(_CDLL, f"PGM_{name}").argtypes = [HandlePtr] + c_argtypes
169+
getattr(_CDLL, f"PGM_{name}").argtypes = [HandlePtr, *c_argtypes]
170170
getattr(_CDLL, f"PGM_{name}").restype = c_restype
171171

172172
# binding function

src/power_grid_model/_core/power_grid_dataset.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
Power grid model raw dataset handler
77
"""
88

9-
from typing import Any, Mapping, cast
9+
from collections.abc import Mapping
10+
from typing import Any, cast
1011

1112
from power_grid_model._core.buffer_handling import (
1213
BufferProperties,

0 commit comments

Comments
 (0)