Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
21 changes: 0 additions & 21 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,27 +34,6 @@ jobs:
pip install ruff
ruff check

pylint:
name: Pylint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
-
uses: actions/setup-python@v6
with:
python-version: '3.x'
- name: "Main Script"
run: |
EXTRA_INSTALL="numpy sympy scipy pexpect"
curl -L -O https://tiker.net/ci-support-v0
. ./ci-support-v0
build_py_project_in_venv

# https://github.com/inducer/pymbolic/pull/66#issuecomment-950371315
pip install symengine || true

run_pylint pymbolic test/test_*.py

basedpyright:
runs-on: ubuntu-latest

Expand Down
11 changes: 0 additions & 11 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,6 @@ Python 3 Conda:
reports:
junit: test/pytest.xml

Pylint:
script:
- EXTRA_INSTALL="numpy sympy symengine scipy pexpect"
- PY_EXE=python3
- curl -L -O https://gitlab.tiker.net/inducer/ci-support/raw/main/prepare-and-run-pylint.sh
- ". ./prepare-and-run-pylint.sh pymbolic test/test_*.py"
tags:
- python3
except:
- tags

Documentation:
script:
- EXTRA_INSTALL="numpy sympy"
Expand Down
3 changes: 0 additions & 3 deletions .pylintrc-local.yml

This file was deleted.

2 changes: 1 addition & 1 deletion pymbolic/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
RealNumber,
Scalar,
)
from pymbolic.version import VERSION_TEXT as __version__ # noqa
from pymbolic.version import VERSION_TEXT as __version__ # noqa: F401,N811


__all__ = (
Expand Down
10 changes: 5 additions & 5 deletions pymbolic/algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,12 @@ def extended_euclidean(q, r):
p, a, b = extended_euclidean(r, q)
return p, b, a

Q = 1, 0 # noqa
R = 0, 1 # noqa
Q = 1, 0 # noqa: N806
R = 0, 1 # noqa: N806

while r:
quot, t = divmod(q, r)
T = Q[0] - quot*R[0], Q[1] - quot*R[1] # noqa
T = Q[0] - quot*R[0], Q[1] - quot*R[1] # noqa: N806
q, r = r, t
Q, R = R, T # noqa: N806

Expand Down Expand Up @@ -299,7 +299,7 @@ def wrap_intermediate_with_level(level: int, x):
# }}}


def csr_matrix_multiply(S, x): # noqa
def csr_matrix_multiply(S, x): # noqa: N803
"""Multiplies a :class:`scipy.sparse.csr_matrix` S by an object-array vector x.
"""
h, _w = S.shape
Expand All @@ -308,7 +308,7 @@ def csr_matrix_multiply(S, x): # noqa
result = numpy.empty_like(x)

for i in range(h):
result[i] = sum(S.data[idx]*x[S.indices[idx]] # pylint:disable=unsupported-assignment-operation
result[i] = sum(S.data[idx]*x[S.indices[idx]]
for idx in range(S.indptr[i], S.indptr[i+1]))

return result
Expand Down
26 changes: 13 additions & 13 deletions pymbolic/interop/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
ast.BitAnd: p.BitwiseAnd,
}

def map_BinOp(self, expr): # noqa
def map_BinOp(self, expr): # noqa: N802
try:
op_constructor = self.bin_op_map[type(expr.op)]
except KeyError:
Expand All @@ -155,7 +155,7 @@
ast.USub: _neg,
}

def map_UnaryOp(self, expr): # noqa
def map_UnaryOp(self, expr): # noqa: N802
try:
op_constructor = self.unary_op_map[type(expr.op)]
except KeyError:
Expand All @@ -165,7 +165,7 @@

return op_constructor(self.rec(expr.operand))

def map_IfExp(self, expr): # noqa
def map_IfExp(self, expr): # noqa: N802
# (expr test, expr body, expr orelse)
return p.If(self.rec(expr.test), self.rec(expr.body), self.rec(expr.orelse))

Expand All @@ -182,7 +182,7 @@
# NotIn
}

def map_Compare(self, expr): # noqa
def map_Compare(self, expr): # noqa: N802
# (expr left, cmpop* ops, expr* comparators)
op, = expr.ops

Expand All @@ -198,37 +198,37 @@

return p.Comparison(self.rec(expr.left), comp, self.rec(right))

def map_Call(self, expr): # noqa
def map_Call(self, expr): # noqa: N802
# (expr func, expr* args, keyword* keywords)
func = self.rec(expr.func)
args = tuple([self.rec(arg) for arg in expr.args])
if getattr(expr, "keywords", []):
return p.CallWithKwargs(func, args,

Check warning on line 206 in pymbolic/interop/ast.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.10

CallWithKwargs created with non-hashable kw_parameters. This is deprecated and will stop working in 2025. If you need an immutable mapping, try the :mod:`constantdict` package.

Check warning on line 206 in pymbolic/interop/ast.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.10

CallWithKwargs created with non-hashable kw_parameters. This is deprecated and will stop working in 2025. If you need an immutable mapping, try the :mod:`constantdict` package.
{
kw.arg: self.rec(kw.value)
for kw in expr.keywords})
else:
return p.Call(func, args)

def map_Num(self, expr): # noqa
def map_Num(self, expr): # noqa: N802
# (object n) -- a number as a PyObject.
return expr.n

def map_Str(self, expr): # noqa
def map_Str(self, expr): # noqa: N802
return expr.s

def map_Bytes(self, expr): # noqa
def map_Bytes(self, expr): # noqa: N802
return expr.s

def map_Constant(self, expr): # noqa
def map_Constant(self, expr): # noqa: N802
# (singleton value)
return expr.value

def map_Attribute(self, expr): # noqa
def map_Attribute(self, expr): # noqa: N802
# (expr value, identifier attr, expr_context ctx)
return p.Lookup(self.rec(expr.value), expr.attr)

def map_Subscript(self, expr): # noqa
def map_Subscript(self, expr): # noqa: N802
# (expr value, slice slice, expr_context ctx)
def none_or_rec(x):
if x is None:
Expand All @@ -250,11 +250,11 @@

# def map_Starred(self, expr):

def map_Name(self, expr): # noqa
def map_Name(self, expr): # noqa: N802
# (identifier id, expr_context ctx)
return p.Variable(expr.id)

def map_Tuple(self, expr): # noqa
def map_Tuple(self, expr): # noqa: N802
# (expr* elts, expr_context ctx)
return tuple([self.rec(ti) for ti in expr.elts])

Expand Down
18 changes: 9 additions & 9 deletions pymbolic/interop/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ def function_name(self, expr):

# }}}

def map_Symbol(self, expr): # noqa
def map_Symbol(self, expr): # noqa: N802
return prim.Variable(str(expr.name))

def map_Rational(self, expr): # noqa
def map_Rational(self, expr): # noqa: N802
p, q = expr.p, expr.q

num = self.rec(p)
Expand All @@ -88,30 +88,30 @@ def map_Rational(self, expr): # noqa
return num
return prim.Quotient(num, denom)

def map_Integer(self, expr): # noqa
def map_Integer(self, expr): # noqa: N802
return int(expr)

def map_Add(self, expr): # noqa
def map_Add(self, expr): # noqa: N802
return prim.Sum(tuple([self.rec(arg) for arg in expr.args]))

def map_Mul(self, expr): # noqa
def map_Mul(self, expr): # noqa: N802
return prim.Product(tuple([self.rec(arg) for arg in expr.args]))

def map_Pow(self, expr): # noqa
def map_Pow(self, expr): # noqa: N802
base, exp = expr.args
return prim.Power(self.rec(base), self.rec(exp))

def map_Subs(self, expr): # noqa
def map_Subs(self, expr): # noqa: N802
return prim.Substitution(self.rec(expr.expr),
tuple([v.name for v in expr.variables]),
tuple([self.rec(v) for v in expr.point]),
)

def map_Derivative(self, expr): # noqa
def map_Derivative(self, expr): # noqa: N802
return prim.Derivative(self.rec(expr.expr),
tuple([v.name for v in expr.variables]))

def map_UnevaluatedExpr(self, expr): # noqa
def map_UnevaluatedExpr(self, expr): # noqa: N802
return self.rec(expr.args[0])

def not_supported(self, expr):
Expand Down
2 changes: 0 additions & 2 deletions pymbolic/interop/matchpy/tofrom.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,13 @@ def map_logical_and(self, expr: p.LogicalAnd) -> m.LogicalAnd:

@override
def map_comparison(self, expr: p.Comparison) -> m.Comparison:
# pylint: disable=too-many-function-args
return m.Comparison(self.rec(expr.left),
m.ComparisonOp(expr.operator),
self.rec(expr.right),
)

@override
def map_if(self, expr: p.If) -> m.If:
# pylint: disable=too-many-function-args
return m.If(self.rec(expr.condition),
self.rec(expr.then),
self.rec(expr.else_))
Expand Down
4 changes: 2 additions & 2 deletions pymbolic/interop/maxima.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,9 @@ def __init__(self, executable="maxima", timeout=30):

def _initialize(self):

PEXPECT_SHELL = "bash" # noqa
PEXPECT_SHELL = "bash" # noqa: N806

PRE_MAXIMA_COMMANDS = ( # noqa
PRE_MAXIMA_COMMANDS = ( # noqa: N806
# Makes long line inputs possible.
("stty -icanon",)
)
Expand Down
12 changes: 6 additions & 6 deletions pymbolic/interop/symengine.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,25 +46,25 @@

class SymEngineToPymbolicMapper(SympyLikeToPymbolicMapper):

def map_Pow(self, expr): # noqa
def map_Pow(self, expr): # noqa: N802
# SymEngine likes to use as e**a to express exp(a); we undo that here.
base, exp = expr.args
if base == symengine.E:
return prim.Variable("exp")(self.rec(exp))
else:
return prim.Power(self.rec(base), self.rec(exp))

def map_Constant(self, expr): # noqa
def map_Constant(self, expr): # noqa: N802
return self.rec(expr.n())

map_Complex = map_Constant # noqa: N815

def map_ComplexDouble(self, expr): # noqa
def map_ComplexDouble(self, expr): # noqa: N802
return complex(expr)

map_RealDouble = SympyLikeToPymbolicMapper.to_float # noqa: N815

def map_Piecewise(self, expr): # noqa
def map_Piecewise(self, expr): # noqa: N802
# We only handle piecewises with 2 statements!
if not len(expr.args) == 4:
raise NotImplementedError
Expand All @@ -84,9 +84,9 @@ def function_name(self, expr):
return type(expr).__name__

def not_supported(self, expr):
from symengine.lib.symengine_wrapper import PyFunction # pylint: disable=E0611
from symengine.lib.symengine_wrapper import PyFunction
if isinstance(expr, PyFunction) and \
self.function_name(expr) == "CSE": # pylint: disable=E0611
self.function_name(expr) == "CSE":
sympy_expr = expr._sympy_()
return prim.CommonSubexpression(
self.rec(expr.args[0]), sympy_expr.prefix, sympy_expr.scope)
Expand Down
10 changes: 5 additions & 5 deletions pymbolic/interop/sympy.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

class SympyToPymbolicMapper(SympyLikeToPymbolicMapper):

def map_ImaginaryUnit(self, expr): # noqa
def map_ImaginaryUnit(self, expr): # noqa: N802
return 1j

map_Float = SympyLikeToPymbolicMapper.to_float # noqa: N815
Expand All @@ -59,9 +59,9 @@ def function_name(self, expr):

# only called for Py2
def map_long(self, expr):
return long(expr) # noqa pylint:disable=undefined-variable
return long(expr) # noqa: F821

def map_Indexed(self, expr): # noqa
def map_Indexed(self, expr): # noqa: N802
if len(expr.args) == 2:
return prim.Subscript(
self.rec(expr.args[0].args[0]),
Expand All @@ -73,11 +73,11 @@ def map_Indexed(self, expr): # noqa
tuple([self.rec(i) for i in expr.args[1:]])
)

def map_CSE(self, expr): # noqa
def map_CSE(self, expr): # noqa: N802
return prim.CommonSubexpression(
self.rec(expr.args[0]), expr.prefix, expr.scope)

def map_Piecewise(self, expr): # noqa
def map_Piecewise(self, expr): # noqa: N802
# We only handle piecewises with 2 arguments!
if not len(expr.args) == 2:
raise NotImplementedError
Expand Down
10 changes: 4 additions & 6 deletions pymbolic/mapper/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,7 @@
ResultT = TypeVar("ResultT")

# This ParamSpec could be marked contravariant (just like Callable is contravariant
# in its arguments). As of mypy 1.14/Py3.13 (Nov 2024), mypy complains of as-yet
# undefined semantics, so it's probably too soon.
# in its arguments). Unfortunately, this is not yet supported by type checkers.
P = ParamSpec("P")


Expand Down Expand Up @@ -203,7 +202,7 @@
else:
return self.handle_unsupported_expression(expr, *args, **kwargs)
else:
return self.map_foreign(expr, *args, **kwargs)

Check warning on line 205 in pymbolic/mapper/__init__.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.10

List found in expression graph. This is deprecated and will stop working in 2025. Use tuples instead.

Check warning on line 205 in pymbolic/mapper/__init__.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.10

List found in expression graph. This is deprecated and will stop working in 2025. Use tuples instead.

Check warning on line 205 in pymbolic/mapper/__init__.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.10

List found in expression graph. This is deprecated and will stop working in 2025. Use tuples instead.

Check warning on line 205 in pymbolic/mapper/__init__.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.10

List found in expression graph. This is deprecated and will stop working in 2025. Use tuples instead.

Check warning on line 205 in pymbolic/mapper/__init__.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.10

List found in expression graph. This is deprecated and will stop working in 2025. Use tuples instead.

Check warning on line 205 in pymbolic/mapper/__init__.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.10

List found in expression graph. This is deprecated and will stop working in 2025. Use tuples instead.

rec = __call__

Expand Down Expand Up @@ -1058,7 +1057,7 @@
) -> Expression:

# True fact: lists aren't expressions
return [self.rec(child, *args, **kwargs) for child in expr] # type: ignore[return-value]
return [self.rec(child, *args, **kwargs) for child in expr]

@override
def map_tuple(self,
Expand All @@ -1081,8 +1080,7 @@
for i in ndindex(expr.shape):
result[i] = self.rec(expr[i], *args, **kwargs)

# True fact: ndarrays aren't expressions
return result # type: ignore[return-value]
return result

@override
def map_multivector(self,
Expand All @@ -1091,7 +1089,7 @@
) -> Expression:
# True fact: MultiVectors aren't expressions
return expr.map(lambda ch: cast("ArithmeticExpression",
self.rec(ch, *args, **kwargs))) # type: ignore[return-value]
self.rec(ch, *args, **kwargs)))

def map_common_subexpression(self,
expr: p.CommonSubexpression,
Expand Down
4 changes: 2 additions & 2 deletions pymbolic/mapper/constant_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ def __init__(self, real_type, complex_type=None, integer_type=None):
complex_type = np.complex64
elif real_type is np.float64:
complex_type = np.complex128
elif real_type is np.float128: # pylint:disable=no-member
complex_type = np.complex256 # pylint:disable=no-member
elif real_type is np.float128:
complex_type = np.complex256
else:
raise TypeError("unable to determine corresponding complex type "
f"for '{real_type.__name__}'")
Expand Down
3 changes: 1 addition & 2 deletions pymbolic/mapper/dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,7 @@ def map_common_subexpression_uncached(
if self.include_cses:
return {expr}
else:
# FIXME: These look like mypy bugs, revisit
return Collector.map_common_subexpression(self, expr, *args, **kwargs) # type: ignore[return-value, arg-type]
return Collector.map_common_subexpression(self, expr, *args, **kwargs)

@override
def map_slice(
Expand Down
Loading
Loading