From 2558bbb738440bf71d522d2bf973cc132a2f2ef3 Mon Sep 17 00:00:00 2001 From: Alexandru Fikl Date: Fri, 20 Feb 2026 16:56:30 +0200 Subject: [PATCH 1/3] fix: some non-enabled ruff errors --- pymbolic/algorithm.py | 2 +- pymbolic/geometric_algebra/__init__.py | 27 ++++++++++++------------ pymbolic/geometric_algebra/mapper.py | 2 +- pymbolic/geometric_algebra/primitives.py | 2 +- pymbolic/interop/ast.py | 10 ++++----- pymbolic/mapper/__init__.py | 2 +- pymbolic/mapper/coefficient.py | 4 ++-- pymbolic/primitives.py | 9 ++------ pymbolic/rational.py | 16 +++++++------- test/test_maxima.py | 6 +++--- 10 files changed, 37 insertions(+), 43 deletions(-) diff --git a/pymbolic/algorithm.py b/pymbolic/algorithm.py index 43757f3b..8722bf10 100644 --- a/pymbolic/algorithm.py +++ b/pymbolic/algorithm.py @@ -112,7 +112,7 @@ def extended_euclidean(q, r): `Wikipedia article on the Euclidean algorithm `__. """ - import pymbolic.traits as traits + from pymbolic import traits # see [Davenport], Appendix, p. 214 diff --git a/pymbolic/geometric_algebra/__init__.py b/pymbolic/geometric_algebra/__init__.py index 87cfa75c..a9bdb37e 100644 --- a/pymbolic/geometric_algebra/__init__.py +++ b/pymbolic/geometric_algebra/__init__.py @@ -42,8 +42,7 @@ import numpy as np from typing_extensions import Self, override -import pytools.obj_array as obj_array -from pytools import memoize, memoize_method +from pytools import memoize, memoize_method, obj_array from pytools.obj_array import ObjectArray, ObjectArray1D, ShapeT from pymbolic.primitives import expr_dataclass, is_zero @@ -1103,10 +1102,10 @@ def project(self, r: int) -> MultiVector[CoeffT]: Often written :math:`\langle A\rangle_r`. """ - new_data: dict[int, CoeffT] = {} - for bits, coeff in self.data.items(): - if bits.bit_count() == r: - new_data[bits] = coeff + new_data: dict[int, CoeffT] = { + bits: coeff for bits, coeff in self.data.items() + if bits.bit_count() == r + } return MultiVector(new_data, self.space) @@ -1161,19 +1160,19 @@ def get_pure_grade(self) -> int | None: def odd(self) -> MultiVector[CoeffT]: """Extract the odd-grade blades.""" - new_data: dict[int, CoeffT] = {} - for bits, coeff in self.data.items(): - if bits.bit_count() % 2: - new_data[bits] = coeff + new_data: dict[int, CoeffT] = { + bits: coeff for bits, coeff in self.data.items() + if bits.bit_count() % 2 == 1 + } return MultiVector(new_data, self.space) def even(self) -> MultiVector[CoeffT]: """Extract the even-grade blades.""" - new_data: dict[int, CoeffT] = {} - for bits, coeff in self.data.items(): - if bits.bit_count() % 2 == 0: - new_data[bits] = coeff + new_data: dict[int, CoeffT] = { + bits: coeff for bits, coeff in self.data.items() + if bits.bit_count() % 2 == 0 + } return MultiVector(new_data, self.space) diff --git a/pymbolic/geometric_algebra/mapper.py b/pymbolic/geometric_algebra/mapper.py index 138df5ec..fdee154f 100644 --- a/pymbolic/geometric_algebra/mapper.py +++ b/pymbolic/geometric_algebra/mapper.py @@ -32,7 +32,7 @@ from typing_extensions import Self, override -import pytools.obj_array as obj_array +from pytools import obj_array import pymbolic.geometric_algebra.primitives as gp from pymbolic.geometric_algebra import MultiVector diff --git a/pymbolic/geometric_algebra/primitives.py b/pymbolic/geometric_algebra/primitives.py index 8e5a17bf..9e4f1bd2 100644 --- a/pymbolic/geometric_algebra/primitives.py +++ b/pymbolic/geometric_algebra/primitives.py @@ -31,7 +31,7 @@ from typing_extensions import override -import pytools.obj_array as obj_array +from pytools import obj_array from pymbolic.geometric_algebra import MultiVector from pymbolic.primitives import ExpressionNode, Variable, expr_dataclass diff --git a/pymbolic/interop/ast.py b/pymbolic/interop/ast.py index 784ab917..77025810 100644 --- a/pymbolic/interop/ast.py +++ b/pymbolic/interop/ast.py @@ -46,16 +46,16 @@ from pymbolic.geometric_algebra import MultiVector # NOTE: these are removed in Python 3.14 - if sys.version_info < (3, 14): + if sys.version_info >= (3, 14): + AstNum: TypeAlias = Any + AstStr: TypeAlias = Any + AstBytes: TypeAlias = Any + else: from ast import ( Bytes as AstBytes, # pyright: ignore[reportDeprecated] Num as AstNum, # pyright: ignore[reportDeprecated] Str as AstStr, # pyright: ignore[reportDeprecated] ) - else: - AstNum: TypeAlias = Any - AstStr: TypeAlias = Any - AstBytes: TypeAlias = Any __doc__ = r''' An example: diff --git a/pymbolic/mapper/__init__.py b/pymbolic/mapper/__init__.py index 44d402d6..5d285408 100644 --- a/pymbolic/mapper/__init__.py +++ b/pymbolic/mapper/__init__.py @@ -1441,7 +1441,7 @@ def map_multivector(self, if not self.visit(expr, *args, **kwargs): return - for _bits, coeff in expr.data.items(): + for coeff in expr.data.values(): self.rec(coeff, *args, **kwargs) self.post_visit(expr, *args, **kwargs) diff --git a/pymbolic/mapper/coefficient.py b/pymbolic/mapper/coefficient.py index bb499768..fdaff2af 100644 --- a/pymbolic/mapper/coefficient.py +++ b/pymbolic/mapper/coefficient.py @@ -91,8 +91,8 @@ def map_quotient(self, expr: p.Quotient, /) -> CoeffsT: if len(d_den) > 1 or 1 not in d_den: raise RuntimeError("nonlinear expression") val = d_den[1] - for k in d_num: - d_num[k] = p.flattened_product((d_num[k], p.Quotient(1, val))) + for k, v in d_num.items(): + d_num[k] = p.flattened_product((v, p.Quotient(1, val))) return d_num @override diff --git a/pymbolic/primitives.py b/pymbolic/primitives.py index da6fdb8c..03bf35f2 100644 --- a/pymbolic/primitives.py +++ b/pymbolic/primitives.py @@ -46,8 +46,7 @@ from constantdict import constantdict from typing_extensions import Self, TypeIs, dataclass_transform, override -import pytools.obj_array as obj_array -from pytools import T, module_getattr_for_deprecations, ndindex +from pytools import T, module_getattr_for_deprecations, ndindex, obj_array from pytools.obj_array import ( ObjectArray, ObjectArray1D, @@ -909,7 +908,7 @@ def __iter__(self) -> NoReturn: (?<=[A-Z]) # preceded by lowercase (?=[A-Z][a-z]) # followed by uppercase, then lowercase """, - re.X, + re.VERBOSE, ) @@ -1123,14 +1122,12 @@ class AlgebraicLeaf(ExpressionNode): """An expression that serves as a leaf for arithmetic evaluation. This may end up having child nodes still, but they're not reached by ways of arithmetic.""" - pass @expr_dataclass() class Leaf(AlgebraicLeaf): """An expression that is irreducible, i.e. has no Expression-type parts whatsoever.""" - pass @expr_dataclass() @@ -1807,8 +1804,6 @@ def quotient(numerator: ArithmeticExpression, # {{{ tool functions -global VALID_CONSTANT_CLASSES -global VALID_OPERANDS VALID_CONSTANT_CLASSES: tuple[type, ...] = (int, float, complex) _BOOL_CLASSES: tuple[type, ...] = (bool,) VALID_OPERANDS = (ExpressionNode,) diff --git a/pymbolic/rational.py b/pymbolic/rational.py index b966af6a..1c787593 100644 --- a/pymbolic/rational.py +++ b/pymbolic/rational.py @@ -25,11 +25,11 @@ from sys import intern -import pymbolic.primitives as primitives -import pymbolic.traits as traits +import pymbolic.primitives as prim +from pymbolic import traits -class Rational(primitives.ExpressionNode): +class Rational(prim.ExpressionNode): def __init__(self, numerator, denominator=1): d_unit = traits.traits(denominator).get_unit(denominator) numerator /= d_unit @@ -67,11 +67,11 @@ def __add__(self, other): newnum = self.Numerator * newden/self.Denominator + \ newother.Numerator * newden/newother.Denominator gcd = t.gcd(newden, newnum) - return primitives.quotient(newnum/gcd, newden/gcd) + return prim.quotient(newnum/gcd, newden/gcd) except traits.NoTraitsError: - return primitives.ExpressionNode.__add__(self, other) + return prim.Sum((self, other)) except traits.NoCommonTraitsError: - return primitives.ExpressionNode.__add__(self, other) + return prim.Sum((self, other)) __radd__ = __add__ @@ -98,9 +98,9 @@ def __mul__(self, other): return Rational(new_num, new_denom) except traits.NoTraitsError: - return primitives.ExpressionNode.__mul__(self, other) + return prim.Product((self, other)) except traits.NoCommonTraitsError: - return primitives.ExpressionNode.__mul__(self, other) + return prim.Product((self, other)) __rmul__ = __mul__ diff --git a/test/test_maxima.py b/test/test_maxima.py index eacea8d8..25b5278e 100644 --- a/test/test_maxima.py +++ b/test/test_maxima.py @@ -103,11 +103,11 @@ def test_strict_round_trip(knl: MaximaKernel) -> None: round_trips_correctly = result == expr if not round_trips_correctly: print("ORIGINAL:") - print("") + print() print(expr) - print("") + print() print("POST-MAXIMA:") - print("") + print() print(result) assert round_trips_correctly From 5f7144facc47b4d3ab1c113cda3dc27722ca082f Mon Sep 17 00:00:00 2001 From: Alexandru Fikl Date: Fri, 20 Feb 2026 16:56:47 +0200 Subject: [PATCH 2/3] chore: use select instead of extend-select for ruff --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 191638ad..fdac27ac 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -64,7 +64,7 @@ exclude = [ preview = true [tool.ruff.lint] -extend-select = [ +select = [ "B", # flake8-bugbear "C", # flake8-comprehensions "E", # pycodestyle From ab882b5e4c57e050bfa44ef96fd0ed335f9ad8ab Mon Sep 17 00:00:00 2001 From: Alexandru Fikl Date: Fri, 20 Feb 2026 19:40:57 +0200 Subject: [PATCH 3/3] chore: update baseline --- .basedpyright/baseline.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.basedpyright/baseline.json b/.basedpyright/baseline.json index 779d45e4..98ee8d53 100644 --- a/.basedpyright/baseline.json +++ b/.basedpyright/baseline.json @@ -9608,16 +9608,16 @@ { "code": "reportUnknownArgumentType", "range": { - "startColumn": 39, - "endColumn": 49, + "startColumn": 33, + "endColumn": 43, "lineCount": 1 } }, { "code": "reportUnknownArgumentType", "range": { - "startColumn": 51, - "endColumn": 61, + "startColumn": 45, + "endColumn": 55, "lineCount": 1 } },