From bb2511534061e1e3c30c45f4ea602a308e494d1e Mon Sep 17 00:00:00 2001 From: Claas Date: Mon, 6 Jan 2025 11:03:56 +0100 Subject: [PATCH 1/7] ruff.toml : removed deprecated ruff rules ANN101 and ANN102 from excluded rules --- ruff.toml | 2 -- 1 file changed, 2 deletions(-) diff --git a/ruff.toml b/ruff.toml index 87ed7f1e..c6df47af 100644 --- a/ruff.toml +++ b/ruff.toml @@ -28,8 +28,6 @@ ignore = [ "PLR0912", # Too many branches <- @TODO: reactivate and resolve @CLAROS, 2024-10-21 "PLR0915", # Too many statements <- @TODO: reactivate and resolve @CLAROS, 2024-10-21 # Ruff lint rules considered as too strict and hence ignored - "ANN101", # Missing type annotation for `self` argument in instance methods (NOTE: also listed as deprecated by Ruff) - "ANN102", # Missing type annotation for `cls` argument in class methods (NOTE: also listed as deprecated by Ruff) "FIX002", # Line contains TODO, consider resolving the issue "TD003", # Missing issue link on the line following a TODO "S101", # Use of assert detected From aea47d0d0b2ad09271a01b9791206155811d3c40 Mon Sep 17 00:00:00 2001 From: Claas Date: Mon, 6 Jan 2025 11:05:35 +0100 Subject: [PATCH 2/7] src/farn/sampling/sampling.py : use f-string instead of '%' style string formatting --- src/farn/sampling/sampling.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/farn/sampling/sampling.py b/src/farn/sampling/sampling.py index ca92bf0b..78ffeb95 100644 --- a/src/farn/sampling/sampling.py +++ b/src/farn/sampling/sampling.py @@ -437,7 +437,7 @@ def _generate_values_using_sobol_sampling(self) -> ndarray[tuple[int,], np.dtype sobol_engine: Sobol = Sobol( d=self.number_of_fields, scramble=False, - seed=None, + rng=None, ) if self.onset > 0: @@ -601,9 +601,8 @@ def _generate_case_names( self, samples: dict[str, list[Any]], ) -> None: - self.case_names = [ - f'{self.layer_name}_{format(i, "0%i" % self.leading_zeros)}' for i in range(self.number_of_samples) - ] + _format_specifier: str = f"0{self.leading_zeros}i" + self.case_names = [f"{self.layer_name}_{format(i, _format_specifier)}" for i in range(self.number_of_samples)] samples["_case_name"] = self.case_names def _check_length_matches_number_of_names( From 70e76aa5a93035c7bc5f29449a48718f5a47d725 Mon Sep 17 00:00:00 2001 From: Claas Date: Mon, 6 Jan 2025 11:06:09 +0100 Subject: [PATCH 3/7] src/farn/cli/farn.py : use f-string instead of '%' style string formatting --- src/farn/cli/farn.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/farn/cli/farn.py b/src/farn/cli/farn.py index 03bf593f..54dea768 100755 --- a/src/farn/cli/farn.py +++ b/src/farn/cli/farn.py @@ -300,13 +300,7 @@ def t4(p: tuple[float, float]) -> tuple[float, float]: screen_width = root.winfo_screenwidth() screen_height = root.winfo_screenheight() root.geometry( - "%dx%d+%d+%d" - % ( - x_size, - y_size, - screen_width / 2 - x_size / 2, - screen_height / 2 - y_size / 2, - ) + newGeometry=f"{x_size}x{y_size}+{int(screen_width / 2 - x_size / 2)}+{int(screen_height / 2 - y_size / 2)}" ) image = tk.PhotoImage(file=temp_file) canvas = tk.Canvas(root, height=y_size, width=x_size, bg="dark slate gray") From fa6ace1c03a673c42cab4e6e026d43cd71fe42c1 Mon Sep 17 00:00:00 2001 From: Claas Date: Mon, 6 Jan 2025 11:07:05 +0100 Subject: [PATCH 4/7] src/farn/core/case.py : made signature of `def __eq__()` method PEP 570 compliant --- src/farn/core/case.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/farn/core/case.py b/src/farn/core/case.py index 9c7e173a..235417ee 100644 --- a/src/farn/core/case.py +++ b/src/farn/core/case.py @@ -264,8 +264,8 @@ def to_dict(self) -> dict[str, Any]: def __str__(self) -> str: return str(self.to_dict()) - def __eq__(self, __o: object) -> bool: - return str(self) == str(__o) + def __eq__(self, other: object) -> bool: + return str(self) == str(other) class Cases(list[Case]): From f28d8df6d60debb4889c204ccfdcad7debc4387d Mon Sep 17 00:00:00 2001 From: Claas Date: Mon, 6 Jan 2025 11:18:53 +0100 Subject: [PATCH 5/7] src/farn/sampling/sampling.py : corrected format specifier --- src/farn/sampling/sampling.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/farn/sampling/sampling.py b/src/farn/sampling/sampling.py index 78ffeb95..0a70f6c9 100644 --- a/src/farn/sampling/sampling.py +++ b/src/farn/sampling/sampling.py @@ -601,7 +601,7 @@ def _generate_case_names( self, samples: dict[str, list[Any]], ) -> None: - _format_specifier: str = f"0{self.leading_zeros}i" + _format_specifier: str = f"0{self.leading_zeros}d" self.case_names = [f"{self.layer_name}_{format(i, _format_specifier)}" for i in range(self.number_of_samples)] samples["_case_name"] = self.case_names From f7eb54d4ef045069de63260b4381de21f06c8bfa Mon Sep 17 00:00:00 2001 From: Claas Date: Mon, 6 Jan 2025 12:04:48 +0100 Subject: [PATCH 6/7] src/farn/core/case.py : changed the way how local variables get added / manipulated through code. Replaced access to `locals()` with `sys._getframe().f_locals` when manipulating local variables. This change became necessary as Python 3.13 changed the way Python's builtin `locals()` method works. See PEP 667 for details. https://peps.python.org/pep-0667/ --- src/farn/core/case.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/farn/core/case.py b/src/farn/core/case.py index 235417ee..61f91d55 100644 --- a/src/farn/core/case.py +++ b/src/farn/core/case.py @@ -4,6 +4,7 @@ import logging import re +import sys from collections.abc import MutableMapping, MutableSequence, Sequence from copy import deepcopy from enum import IntEnum @@ -136,7 +137,7 @@ def is_valid(self) -> bool: ) return False - # transfer a white list of case properties to locals() for subsequent filtering + # transfer a white list of case properties to frame.f_locals for subsequent filtering available_vars: set[str] = set() for attribute in dir(self): try: @@ -150,7 +151,7 @@ def is_valid(self) -> bool: "condition", "command_sets", ]: - locals()[attribute] = eval(f"self.{attribute}") # noqa: S307 + sys._getframe().f_locals[attribute] = eval(f"self.{attribute}") # noqa: S307, SLF001 # type: ignore[reportPrivateUsage] available_vars.add(attribute) except Exception: # noqa: PERF203 logger.exception( @@ -164,7 +165,7 @@ def is_valid(self) -> bool: for parameter in self.parameters: if parameter.name and not re.match("^_", parameter.name): try: - exec(f"{parameter.name} = {parameter.value}") # noqa: S102 + sys._getframe().f_locals[parameter.name] = parameter.value # noqa: SLF001 # type: ignore[reportPrivateUsage] available_vars.add(parameter.name) except Exception: logger.exception( From 196b7e720600578e71b1819aa7edc28195fcef39 Mon Sep 17 00:00:00 2001 From: Claas Date: Mon, 6 Jan 2025 12:09:48 +0100 Subject: [PATCH 7/7] updated CHANGELOG.md --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4cc48e21..960388ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,13 @@ The changelog format is based on [Keep a Changelog](https://keepachangelog.com/e ## [Unreleased] +### Changed +* ruff.toml : removed deprecated ruff rules ANN101 and ANN102 from excluded rules +* Use f-string, where possible, instead of '%' style string formatting + +### Solved +* src/farn/core/case.py : Changed the way how local variables get added / manipulated through code. Replaced access to `locals()` with `sys._getframe().f_locals` when manipulating local variables. This change became necessary as Python 3.13 changed the way Python's builtin `locals()` method works. See [PEP 667](https://peps.python.org/pep-0667/) for details. + ### Dependencies * Updated to ruff>=0.8.3 (from ruff>=0.6.3) * Updated to pyright>=1.1.390 (from pyright>=1.1.378)