diff --git a/.basedpyright/baseline.json b/.basedpyright/baseline.json index bf1ad30fd..dc2e08097 100644 --- a/.basedpyright/baseline.json +++ b/.basedpyright/baseline.json @@ -12145,14 +12145,6 @@ "lineCount": 1 } }, - { - "code": "reportUnknownMemberType", - "range": { - "startColumn": 12, - "endColumn": 29, - "lineCount": 1 - } - }, { "code": "reportUnknownMemberType", "range": { diff --git a/pyproject.toml b/pyproject.toml index 49040c29d..cad86e1d4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -84,6 +84,7 @@ extend-ignore = [ "camelcase-imported-as-acronym", "C90", "non-empty-init-module", + "pytest-parameter-with-default-argument", # numpy random generators---disable for now "numpy-legacy-random", diff --git a/pytato/analysis/__init__.py b/pytato/analysis/__init__.py index a94edc098..9ccfd3d48 100644 --- a/pytato/analysis/__init__.py +++ b/pytato/analysis/__init__.py @@ -602,7 +602,7 @@ def get_num_nodes( class NodeMultiplicityMapper(CachedWalkMapper[[]]): - """ + r""" Computes the multiplicity of each unique node in a DAG. The multiplicity of a node `x` is the number of nodes with distinct `id()`\\ s diff --git a/pytato/array.py b/pytato/array.py index 591347b64..f18cc595e 100644 --- a/pytato/array.py +++ b/pytato/array.py @@ -317,7 +317,7 @@ def normalize_shape_component( from numbers import Number if isinstance(shape, Array | Number): - shape = shape, + shape = (shape,) assert isinstance(shape, Sequence) return tuple(normalize_shape_component(s) for s in shape) @@ -476,7 +476,7 @@ def _dataclass_replace_if_different(self, **kwargs): ) exec_dict = {"cls": cls, "_MODULE_SOURCE_CODE": augment_code} - exec(compile(augment_code, # ruff:ignore[exec-builtin] + exec(compile(augment_code, f"", "exec"), exec_dict) @@ -2636,7 +2636,7 @@ def reshape(array: Array, newshape: int | Sequence[int], from pytools import product if isinstance(newshape, INT_CLASSES): - newshape = newshape, + newshape = (newshape,) if newshape.count(-1) > 1: raise ValueError("can only specify one unknown dimension") @@ -3445,7 +3445,7 @@ def expand_dims(array: Array, axis: tuple[int, ...] | int) -> Array: from pytato.tags import ExpandedDimsReshape if isinstance(axis, int): - axis = axis, + axis = (axis,) output_ndim = array.ndim + len(axis) diff --git a/pytato/reductions.py b/pytato/reductions.py index a616c6e95..72b48fc43 100644 --- a/pytato/reductions.py +++ b/pytato/reductions.py @@ -173,7 +173,7 @@ def _normalize_reduction_axes( return (), tuple(range(len(shape))) if isinstance(reduction_axes, INT_CLASSES): - reduction_axes = reduction_axes, + reduction_axes = (reduction_axes,) if not isinstance(reduction_axes, tuple): raise TypeError("Reduction axes expected to be of type 'NoneType', 'int'" diff --git a/pytato/tags.py b/pytato/tags.py index 426c3c1ba..8f7d715f8 100644 --- a/pytato/tags.py +++ b/pytato/tags.py @@ -165,7 +165,7 @@ def short_str(self, maxlen: int = 100) -> str: # Fallback in case we don't find any file that is not in the pytato/ # directory (should be unlikely). - return self.__repr__() + return repr(self) def __repr__(self) -> str: return "\n " + "\n ".join([str(f) for f in self.frames]) diff --git a/pytato/target/python/__init__.py b/pytato/target/python/__init__.py index efdb02be3..7895ff1c1 100644 --- a/pytato/target/python/__init__.py +++ b/pytato/target/python/__init__.py @@ -87,7 +87,7 @@ def _compiled_function(self) -> Callable[..., Any]: variables_after_execution: dict[str, Any] = { "_MODULE_SOURCE_CODE": self.program # helps pudb } - exec(self.program, variables_after_execution) # ruff:ignore[exec-builtin] + exec(self.program, variables_after_execution) assert callable(variables_after_execution[self.entrypoint]) return variables_after_execution[ # type: ignore[no-any-return] self.entrypoint] diff --git a/pytato/transform/__init__.py b/pytato/transform/__init__.py index ed9160859..33fd16437 100644 --- a/pytato/transform/__init__.py +++ b/pytato/transform/__init__.py @@ -652,7 +652,7 @@ def add( class TransformMapper(CachedMapper[ArrayOrNames, FunctionDefinition, []]): - """Base class for mappers that transform :class:`pytato.array.Array`\\ s into + r"""Base class for mappers that transform :class:`pytato.array.Array`\\ s into other :class:`pytato.array.Array`\\ s. Enables certain operations that can only be done if the mapping results are also diff --git a/pytato/transform/metadata.py b/pytato/transform/metadata.py index 374107cfc..4da53b998 100644 --- a/pytato/transform/metadata.py +++ b/pytato/transform/metadata.py @@ -242,7 +242,7 @@ def record_equation(self, lhs: str, rhs: str) -> None: self.equations.append((lhs, rhs)) def record_equations_from_axes_tags(self, ary: Array) -> None: - """ + r""" Records equations for *ary*\'s axis tags of type :attr:`tag_t`. """ for iaxis, axis in enumerate(ary.axes): diff --git a/test/test_codegen.py b/test/test_codegen.py index 42e94f0cf..0a860bf60 100755 --- a/test/test_codegen.py +++ b/test/test_codegen.py @@ -29,6 +29,7 @@ """ import itertools +import math import operator import sys @@ -675,7 +676,7 @@ def test_binary_math_functions(ctx_factory: cl.CtxFactory, dtype, function_name) cl_ctx = ctx_factory() queue = cl.CommandQueue(cl_ctx) - if np.dtype(dtype).kind == "c" and function_name in ["arctan2"]: + if np.dtype(dtype).kind == "c" and function_name == "arctan2": pytest.skip("Unsupported by loopy.") from numpy.random import default_rng @@ -2072,7 +2073,7 @@ def build_expression(tracer): twice_x_3 = result["twice"] thrice_x_3 = result["thrice"] - return {"foo": 3.14 + twice_x_3, + return {"foo": math.pi + twice_x_3, "bar": 4 * thrice_x_3, "baz": 65 * twice_x, "quux": 7 * twice_x_2} diff --git a/test/test_distributed.py b/test/test_distributed.py index d4ee81b16..8584f815f 100644 --- a/test/test_distributed.py +++ b/test/test_distributed.py @@ -336,7 +336,7 @@ def gen_comm(rdagc): rdagc_no_comm = RandomDAGContext(np.random.default_rng(seed=seed), axis_len=axis_len, use_numpy=True, additional_generators=[ - (comm_fake_prob, lambda rdagc: make_random_dag(rdagc)) + (comm_fake_prob, make_random_dag) ]) res_no_comm_numpy = make_random_dag(rdagc_no_comm) diff --git a/test/test_pytato.py b/test/test_pytato.py index b7a4f8e73..43d8b3ee8 100644 --- a/test/test_pytato.py +++ b/test/test_pytato.py @@ -1379,19 +1379,19 @@ def test_adv_indexing_into_zero_long_axes(): # See https://github.com/inducer/meshmode/issues/321#issuecomment-1105577180 n = pt.make_size_param("n") + a = pt.make_placeholder("a", shape=(0, 10)) + idx = pt.zeros(5, dtype=np.int64) with pytest.raises(IndexError): - a = pt.make_placeholder("a", shape=(0, 10)) - idx = pt.zeros(5, dtype=np.int64) a[idx] + a = pt.make_placeholder("a", shape=(n-n, 10)) + idx = pt.zeros(5, dtype=np.int64) with pytest.raises(IndexError): - a = pt.make_placeholder("a", shape=(n-n, 10)) - idx = pt.zeros(5, dtype=np.int64) a[idx] + a = pt.make_placeholder("a", shape=(n-n-2, 10)) + idx = pt.zeros(5, dtype=np.int64) with pytest.raises(IndexError): - a = pt.make_placeholder("a", shape=(n-n-2, 10)) - idx = pt.zeros(5, dtype=np.int64) a[idx] # {{{ no index error => sanity checks are working fine diff --git a/test/testlib.py b/test/testlib.py index 0b587f400..963b70c8d 100644 --- a/test/testlib.py +++ b/test/testlib.py @@ -412,8 +412,7 @@ def make_large_dag_with_duplicates(iterations: int, if rng.uniform() > 0.2: dup1 = operation(a, value) dup2 = operation(a, value) - duplicates.append(dup1) - duplicates.append(dup2) + duplicates.extend((dup1, dup2)) current = operation(current, dup1) all_exprs = [current, *duplicates]