Skip to content

Linting and Formatting: adding Pylint checks to Ruff #1025

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 26 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
6a9181b
setup PL checks
Laurynas-Jagutis Jun 18, 2025
7193e10
setup PL checks, update branch
Laurynas-Jagutis Jun 18, 2025
dd9c8ad
adjust pyproject
Laurynas-Jagutis Jun 18, 2025
8bd78aa
update ruff version
Laurynas-Jagutis Jun 18, 2025
b3085ea
Merge remote-tracking branch 'origin/main' into feature/add-PL-checks…
Laurynas-Jagutis Jul 7, 2025
fc79838
investigate why local and remote ruff differs
Laurynas-Jagutis Jul 7, 2025
b2b747f
remove ignore
Laurynas-Jagutis Jul 7, 2025
75e3740
fix issues
Laurynas-Jagutis Jul 7, 2025
8424854
add an example change for PLR2004
Laurynas-Jagutis Jul 7, 2025
e843b8a
change magic values to constants
Laurynas-Jagutis Jul 7, 2025
940009b
Merge remote-tracking branch 'origin/main' into feature/add-PL-checks…
Laurynas-Jagutis Jul 7, 2025
8edceef
change constant name
Laurynas-Jagutis Jul 8, 2025
64e73d9
add some ruff PL fixes to the tests
Laurynas-Jagutis Jul 8, 2025
3f87772
fix PLR5501 in tests
Laurynas-Jagutis Jul 8, 2025
b83d80f
Merge remote-tracking branch 'origin/main' into feature/add-PL-checks…
Laurynas-Jagutis Jul 8, 2025
dfc7248
fix .items() and change ignored checks in tests
Laurynas-Jagutis Jul 8, 2025
719014f
fix magic values1
Laurynas-Jagutis Jul 8, 2025
6e6f25d
fix magic values2
Laurynas-Jagutis Jul 8, 2025
73f3119
Merge remote-tracking branch 'origin/main' into feature/add-PL-checks…
Laurynas-Jagutis Jul 8, 2025
86cd924
adjust pyproject ignore setup
Laurynas-Jagutis Jul 8, 2025
9b2d1ab
Merge remote-tracking branch 'origin/main' into feature/add-PL-checks…
Laurynas-Jagutis Jul 14, 2025
11a236d
update name, capitalize module level constants
Laurynas-Jagutis Jul 14, 2025
467b493
capitalize module level constants
Laurynas-Jagutis Jul 14, 2025
819a42a
capitalize module level constants3
Laurynas-Jagutis Jul 14, 2025
693944d
capitalize module level constants4
Laurynas-Jagutis Jul 14, 2025
d57fedb
add constants for 1D
Laurynas-Jagutis Jul 14, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ repos:
- id: reuse
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.11.12
rev: v0.12.0
hooks:
# Run the linter.
- id: ruff-check
Expand Down
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,10 @@ select = [
"FURB",
"FLY",
"SLOT",
"PL",
"NPY",
]
ignore = ["PLR2004"]

[tool.ruff.lint.isort]
# Imports that are imported using keyword "as" and are from the same source - are combined.
Expand All @@ -123,6 +125,9 @@ combine-as-imports = true
[tool.ruff.lint.per-file-ignores]
# Ignore `F811` (redefinition violations) in all examples notebooks since we use redefinition.
"docs/examples/*.ipynb" = ["F811", "E402"]
# Pylint was only run in src directory before moving to Ruff
"tests/*" = ["PL"]
"setup.py" = ["PL"]

[tool.mypy]
follow_imports = "silent"
Expand Down
2 changes: 1 addition & 1 deletion src/power_grid_model/_core/power_grid_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ def destroy_dataset_mutable(self, dataset: MutableDatasetPtr) -> None: # type:
pass # pragma: no cover

@make_c_binding
def dataset_mutable_add_buffer( # type: ignore[empty-body]
def dataset_mutable_add_buffer( # type: ignore[empty-body] # noqa: PLR0913
self,
dataset: MutableDatasetPtr,
component: str,
Expand Down
14 changes: 7 additions & 7 deletions src/power_grid_model/_core/power_grid_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def _handle_errors(self, continue_on_batch_error: bool, batch_size: int, decode_
decode_error=decode_error,
)

def _calculate_impl(
def _calculate_impl( # noqa: PLR0913
self,
calculation_type: CalculationType,
symmetric: bool,
Expand Down Expand Up @@ -300,7 +300,7 @@ def _calculate_impl(

return output_data

def _calculate_power_flow(
def _calculate_power_flow( # noqa: PLR0913
self,
*,
symmetric: bool = True,
Expand Down Expand Up @@ -337,7 +337,7 @@ def _calculate_power_flow(
experimental_features=experimental_features,
)

def _calculate_state_estimation(
def _calculate_state_estimation( # noqa: PLR0913
self,
*,
symmetric: bool = True,
Expand Down Expand Up @@ -372,7 +372,7 @@ def _calculate_state_estimation(
experimental_features=experimental_features,
)

def _calculate_short_circuit(
def _calculate_short_circuit( # noqa: PLR0913
self,
*,
calculation_method: CalculationMethod | str = CalculationMethod.iec60909,
Expand Down Expand Up @@ -406,7 +406,7 @@ def _calculate_short_circuit(
experimental_features=experimental_features,
)

def calculate_power_flow(
def calculate_power_flow( # noqa: PLR0913
self,
*,
symmetric: bool = True,
Expand Down Expand Up @@ -505,7 +505,7 @@ def calculate_power_flow(
tap_changing_strategy=tap_changing_strategy,
)

def calculate_state_estimation(
def calculate_state_estimation( # noqa: PLR0913
self,
*,
symmetric: bool = True,
Expand Down Expand Up @@ -599,7 +599,7 @@ def calculate_state_estimation(
decode_error=decode_error,
)

def calculate_short_circuit(
def calculate_short_circuit( # noqa: PLR0913
self,
*,
calculation_method: CalculationMethod | str = CalculationMethod.iec60909,
Expand Down
8 changes: 4 additions & 4 deletions src/power_grid_model/validation/_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ def not_less_or_equal(val: np.ndarray, *ref: np.ndarray):
return none_match_comparison(data, component, field, not_less_or_equal, ref_value, NotLessOrEqualError)


def all_between(
def all_between( # noqa: PLR0913
data: SingleDataset,
component: ComponentType,
field: str,
Expand Down Expand Up @@ -281,7 +281,7 @@ def outside(val: np.ndarray, *ref: np.ndarray) -> np.ndarray:
)


def all_between_or_at(
def all_between_or_at( # noqa: PLR0913
data: SingleDataset,
component: ComponentType,
field: str,
Expand Down Expand Up @@ -331,7 +331,7 @@ def outside(val: np.ndarray, *ref: np.ndarray) -> np.ndarray:
)


def none_match_comparison(
def none_match_comparison( # noqa: PLR0913
data: SingleDataset,
component: ComponentType,
field: str,
Expand Down Expand Up @@ -554,7 +554,7 @@ def all_valid_enum_values(
return []


def all_valid_associated_enum_values(
def all_valid_associated_enum_values( # noqa: PLR0913
data: SingleDataset,
component: ComponentType,
field: str,
Expand Down
4 changes: 2 additions & 2 deletions src/power_grid_model/validation/_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ def _process_power_sigma_and_p_q_sigma(
power_sigma[mask] = np.nansum(q_sigma[mask], axis=asym_axes)


def validate_required_values(
def validate_required_values( # noqa: PLR0915
data: SingleDataset, calculation_type: CalculationType | None = None, symmetric: bool = True
) -> list[MissingValueError]:
"""
Expand Down Expand Up @@ -631,7 +631,7 @@ def validate_branch3(data: SingleDataset, component: ComponentType) -> list[Vali
return errors


def validate_three_winding_transformer(data: SingleDataset) -> list[ValidationError]:
def validate_three_winding_transformer(data: SingleDataset) -> list[ValidationError]: # noqa: PLR0915
errors = validate_branch3(data, ComponentType.three_winding_transformer)
errors += _all_greater_than_zero(data, ComponentType.three_winding_transformer, "u1")
errors += _all_greater_than_zero(data, ComponentType.three_winding_transformer, "u2")
Expand Down
Loading