Skip to content

Commit 2c97feb

Browse files
UP check and fixes
Signed-off-by: Laurynas Jagutis <[email protected]>
1 parent 8e54b73 commit 2c97feb

File tree

13 files changed

+33
-23
lines changed

13 files changed

+33
-23
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/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: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,11 @@ select = [
123123
"ARG",
124124
"RET",
125125
"PIE",
126-
"SLF"
126+
"SLF",
127+
"UP"
127128
]
129+
# the rule is deprecated, https://docs.astral.sh/ruff/rules/non-pep604-isinstance/#deprecation
130+
ignore = ["UP038"]
128131

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

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88

99
import os
1010
import platform
11+
from collections.abc import Callable
1112
from ctypes import CDLL, POINTER, c_char, c_char_p, c_double, c_size_t, c_void_p
1213
from inspect import signature
1314
from itertools import chain
1415
from pathlib import Path
15-
from typing import Callable
1616

1717
from power_grid_model._core.index_integer import IdC, IdxC
1818

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,

src/power_grid_model/_core/power_grid_model.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
"""
88

99
from enum import IntEnum
10-
from typing import Type
1110

1211
import numpy as np
1312

@@ -212,7 +211,7 @@ def _construct_output(
212211

213212
@staticmethod
214213
def _options(**kwargs) -> Options:
215-
def as_enum_value(key_enum: str, type_: Type[IntEnum]):
214+
def as_enum_value(key_enum: str, type_: type[IntEnum]):
216215
if key_enum in kwargs:
217216
value_enum = kwargs[key_enum]
218217
if isinstance(value_enum, str):

src/power_grid_model/_core/utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
We do not officially support this functionality and may remove features in this library at any given time!
1111
"""
1212

13+
from collections.abc import Sequence
1314
from copy import deepcopy
14-
from typing import Sequence, cast
15+
from typing import cast
1516

1617
import numpy as np
1718

src/power_grid_model/validation/_rules.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@
3535
3636
"""
3737

38+
from collections.abc import Callable
3839
from enum import Enum
39-
from typing import Any, Callable, Type, TypeVar
40+
from typing import Any, TypeVar
4041

4142
import numpy as np
4243

@@ -336,7 +337,7 @@ def none_match_comparison( # noqa: PLR0913
336337
field: str,
337338
compare_fn: Callable,
338339
ref_value: ComparisonError.RefType,
339-
error: Type[CompError] = ComparisonError, # type: ignore
340+
error: type[CompError] = ComparisonError, # type: ignore
340341
default_value_1: np.ndarray | int | float | None = None,
341342
default_value_2: np.ndarray | int | float | None = None,
342343
) -> list[CompError]:
@@ -524,7 +525,7 @@ def all_in_valid_values(
524525

525526

526527
def all_valid_enum_values(
527-
data: SingleDataset, component: ComponentType, field: str, enum: Type[Enum] | list[Type[Enum]]
528+
data: SingleDataset, component: ComponentType, field: str, enum: type[Enum] | list[type[Enum]]
528529
) -> list[InvalidEnumValueError]:
529530
"""
530531
Check that for all records of a particular type of component, the values in the 'field' column are valid values for
@@ -540,7 +541,7 @@ def all_valid_enum_values(
540541
A list containing zero or one InvalidEnumValueError, listing all ids where the value in the field of interest
541542
was not a valid value in the supplied enum type.
542543
"""
543-
enums: list[Type[Enum]] = enum if isinstance(enum, list) else [enum]
544+
enums: list[type[Enum]] = enum if isinstance(enum, list) else [enum]
544545

545546
valid = {_nan_type(component, field)}
546547
for enum_type in enums:
@@ -559,7 +560,7 @@ def all_valid_associated_enum_values( # noqa: PLR0913
559560
field: str,
560561
ref_object_id_field: str,
561562
ref_components: list[ComponentType],
562-
enum: Type[Enum] | list[Type[Enum]],
563+
enum: type[Enum] | list[type[Enum]],
563564
**filters: Any,
564565
) -> list[InvalidAssociatedEnumValueError]:
565566
"""
@@ -576,7 +577,7 @@ def all_valid_associated_enum_values( # noqa: PLR0913
576577
A list containing zero or one InvalidAssociatedEnumValueError, listing all ids where the value in the field
577578
of interest was not a valid value in the supplied enum type.
578579
"""
579-
enums: list[Type[Enum]] = enum if isinstance(enum, list) else [enum]
580+
enums: list[type[Enum]] = enum if isinstance(enum, list) else [enum]
580581

581582
valid_ids = _get_valid_ids(data=data, ref_components=ref_components)
582583
mask = np.logical_and(

0 commit comments

Comments
 (0)