From 846ff79212950b613c97aafcdd658e54af0f38b9 Mon Sep 17 00:00:00 2001 From: Alexandru Fikl Date: Tue, 23 Jun 2026 17:13:37 +0300 Subject: [PATCH 1/4] chore: bump pyright pythonVersion to 3.12 for numpy --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index b1c41bf6..7e2abac3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -136,7 +136,7 @@ exclude = [ # we care about at this moment. # https://github.com/microsoft/pyright/issues/746 reportImportCycles = "none" -pythonVersion = "3.10" +pythonVersion = "3.12" pythonPlatform = "All" [[tool.basedpyright.executionEnvironments]] From 437dfb32ae5d8d8b0bd63d56400aeae07666eace Mon Sep 17 00:00:00 2001 From: Alexandru Fikl Date: Tue, 23 Jun 2026 17:14:34 +0300 Subject: [PATCH 2/4] chore: remove upper bound from optype --- .github/workflows/ci.yml | 4 ++-- .gitlab-ci.yml | 2 +- pyproject.toml | 3 +-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8a1352ac..b04acb30 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -53,7 +53,7 @@ jobs: python-version: '3.x' - name: "Main Script" run: | - EXTRA_INSTALL="basedpyright numpy attrs orderedsets pytest mpi4py matplotlib optype<0.18" + EXTRA_INSTALL="basedpyright numpy attrs orderedsets pytest mpi4py matplotlib optype" sudo apt update sudo apt -y install libopenmpi-dev @@ -150,7 +150,7 @@ jobs: python-version: '3.x' - name: "Main Script" run: | - EXTRA_INSTALL="numpy optype<0.18" + EXTRA_INSTALL="numpy optype" curl -L -O https://tiker.net/ci-support-v0 . ci-support-v0 build_py_project_in_venv diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 8c9fcbeb..ea58d3cc 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -52,7 +52,7 @@ Ruff: Documentation: script: | - EXTRA_INSTALL="numpy siphash24 optype<0.18" + EXTRA_INSTALL="numpy siphash24 optype" curl -L -O https://gitlab.tiker.net/inducer/ci-support/raw/main/build-docs.sh . ./build-docs.sh tags: diff --git a/pyproject.toml b/pyproject.toml index 7e2abac3..3654f5ed 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -40,8 +40,7 @@ numpy = [ ] test = [ "basedpyright", - # NOTE: 0.18 requires Python 3.12 - "optype<0.18", + "optype", "pytest", "ruff", ] From bf46cacbfae10f2ee5dcf2918b5d179e00f9ca39 Mon Sep 17 00:00:00 2001 From: Alexandru Fikl Date: Tue, 23 Jun 2026 17:20:45 +0300 Subject: [PATCH 3/4] feat(typing): add some type annotations due to pythonVersion bump --- pytools/__init__.py | 3 ++- pytools/convergence.py | 4 ++-- pytools/obj_array.py | 14 +++++++++++--- pytools/py_codegen.py | 11 +++++++---- pytools/test/test_persistent_dict.py | 2 ++ 5 files changed, 24 insertions(+), 10 deletions(-) diff --git a/pytools/__init__.py b/pytools/__init__.py index c1f124b2..3df646c0 100644 --- a/pytools/__init__.py +++ b/pytools/__init__.py @@ -520,6 +520,7 @@ def __getattr__(self, name): class Record(RecordWithoutPickling): __slots__: ClassVar[list[str]] = [] + @override def __getstate__(self): return { key: getattr(self, key) @@ -3352,7 +3353,7 @@ def ndindex(shape: ShapeT) -> Iterable[ShapeT]: """ # undocumented for now import numpy as np - return np.ndindex(shape) + return np.ndindex(shape) # pyright: ignore[reportReturnType] def not_none(obj: T | None) -> T: diff --git a/pytools/convergence.py b/pytools/convergence.py index 19b99306..bea4d9d5 100644 --- a/pytools/convergence.py +++ b/pytools/convergence.py @@ -72,8 +72,8 @@ def add_data_point( def estimate_order_of_convergence(self, gliding_mean: int | None = None, ) -> np.ndarray: - abscissae = np.array([a for a, e in self.history]) - errors = np.array([e for a, e in self.history]) + abscissae = np.array([a for a, e in self.history], dtype=np.float64) + errors = np.array([e for a, e in self.history], dtype=np.float64) # NOTE: in case any of the errors are exactly 0.0, which # can give NaNs in `estimate_order_of_convergence` diff --git a/pytools/obj_array.py b/pytools/obj_array.py index 9e3afc8e..af4cb983 100644 --- a/pytools/obj_array.py +++ b/pytools/obj_array.py @@ -566,12 +566,16 @@ def vectorize( issue described under :func:`new_1d`. """ - import numpy as np if isinstance(ary, ObjectArray): + import numpy as np + + from pytools import ndindex + result = np.empty_like(ary) ary = cast("ObjectArray[ShapeT, T_co]", ary) - for i in np.ndindex(ary.shape): + for i in ndindex(ary.shape): result[i] = f(ary[i]) + return cast("ObjectArray[ShapeT, ResultT]", cast("object", result)) return f(ary) @@ -631,10 +635,14 @@ def rec_vectorize( """ if isinstance(ary, ObjectArray): import numpy as np + + from pytools import ndindex + ary = cast("ObjectArray[ShapeT, object]", ary) result = np.empty_like(ary) - for i in np.ndindex(ary.shape): + for i in ndindex(ary.shape): result[i] = rec_vectorize(f, ary[i]) + return cast("ObjectArray[Any, ShapeT]", cast("object", result)) return f(ary) diff --git a/pytools/py_codegen.py b/pytools/py_codegen.py index 4c915f90..756f9244 100644 --- a/pytools/py_codegen.py +++ b/pytools/py_codegen.py @@ -23,16 +23,13 @@ THE SOFTWARE. """ - import marshal from dataclasses import dataclass, field from importlib.util import MAGIC_NUMBER as BYTECODE_VERSION from types import FunctionType, ModuleType from typing import TYPE_CHECKING, Any, Literal, TypeAlias, cast - -if TYPE_CHECKING: - from collections.abc import Callable, Iterable +from typing_extensions import override from pytools.codegen import ( CodeGenerator as CodeGeneratorBase, @@ -41,6 +38,10 @@ ) +if TYPE_CHECKING: + from collections.abc import Callable, Iterable + + __all__ = ( "ExistingLineCacheWarning", "Indentation", @@ -173,6 +174,7 @@ class PicklableModule: name_prefix: str | None = field(kw_only=True, default=None) source_code: str | None = field(kw_only=True, default=None) + @override def __getstate__(self): functions: _FunctionsType = {} modules: _ModulesType = {} @@ -268,6 +270,7 @@ def _initialize(self, module: PicklableModule, name: str) -> None: def __call__(self, *args: object, **kwargs: object) -> object: return self._callable(*args, **kwargs) # pyright: ignore[reportAny] + @override def __getstate__(self): return {"module": self.module, "name": self.name} diff --git a/pytools/test/test_persistent_dict.py b/pytools/test/test_persistent_dict.py index 49d7b02c..7c48c814 100644 --- a/pytools/test/test_persistent_dict.py +++ b/pytools/test/test_persistent_dict.py @@ -9,6 +9,7 @@ from typing import Any import pytest +from typing_extensions import override from pytools.persistent_dict import ( CollisionWarning, @@ -32,6 +33,7 @@ def __init__(self, val: Any, hash_key=None) -> None: hash_key = val self.hash_key = hash_key + @override def __getstate__(self) -> dict[str, Any]: return {"val": self.val, "hash_key": self.hash_key} From 7018718e699595571de279aba2201ea295587047 Mon Sep 17 00:00:00 2001 From: Alexandru Fikl Date: Tue, 23 Jun 2026 17:21:00 +0300 Subject: [PATCH 4/4] chore: update baseline --- .basedpyright/baseline.json | 180 ++---------------------------------- 1 file changed, 6 insertions(+), 174 deletions(-) diff --git a/.basedpyright/baseline.json b/.basedpyright/baseline.json index 34e994e3..db2bcf60 100644 --- a/.basedpyright/baseline.json +++ b/.basedpyright/baseline.json @@ -3835,30 +3835,6 @@ "lineCount": 1 } }, - { - "code": "reportUnknownMemberType", - "range": { - "startColumn": 11, - "endColumn": 29, - "lineCount": 1 - } - }, - { - "code": "reportUnknownMemberType", - "range": { - "startColumn": 11, - "endColumn": 34, - "lineCount": 1 - } - }, - { - "code": "reportUnknownVariableType", - "range": { - "startColumn": 11, - "endColumn": 36, - "lineCount": 1 - } - }, { "code": "reportAny", "range": { @@ -3890,14 +3866,6 @@ "endColumn": 38, "lineCount": 1 } - }, - { - "code": "reportUnreachable", - "range": { - "startColumn": 12, - "endColumn": 58, - "lineCount": 1 - } } ], "./pytools/convergence.py": [ @@ -4029,30 +3997,6 @@ "lineCount": 1 } }, - { - "code": "reportAny", - "range": { - "startColumn": 8, - "endColumn": 12, - "lineCount": 1 - } - }, - { - "code": "reportUnknownVariableType", - "range": { - "startColumn": 8, - "endColumn": 14, - "lineCount": 1 - } - }, - { - "code": "reportUnknownArgumentType", - "range": { - "startColumn": 45, - "endColumn": 69, - "lineCount": 1 - } - }, { "code": "reportAny", "range": { @@ -5801,22 +5745,6 @@ } ], "./pytools/obj_array.py": [ - { - "code": "reportUnknownVariableType", - "range": { - "startColumn": 12, - "endColumn": 13, - "lineCount": 1 - } - }, - { - "code": "reportUnknownVariableType", - "range": { - "startColumn": 12, - "endColumn": 13, - "lineCount": 1 - } - }, { "code": "reportUnknownParameterType", "range": { @@ -5937,14 +5865,6 @@ "lineCount": 1 } }, - { - "code": "reportUnknownVariableType", - "range": { - "startColumn": 8, - "endColumn": 9, - "lineCount": 1 - } - }, { "code": "reportUnknownMemberType", "range": { @@ -6707,30 +6627,6 @@ "lineCount": 1 } }, - { - "code": "reportUnknownMemberType", - "range": { - "startColumn": 32, - "endColumn": 54, - "lineCount": 1 - } - }, - { - "code": "reportUnknownMemberType", - "range": { - "startColumn": 32, - "endColumn": 64, - "lineCount": 1 - } - }, - { - "code": "reportUnknownArgumentType", - "range": { - "startColumn": 32, - "endColumn": 66, - "lineCount": 1 - } - }, { "code": "reportAny", "range": { @@ -7251,22 +7147,6 @@ "lineCount": 1 } }, - { - "code": "reportUnknownMemberType", - "range": { - "startColumn": 28, - "endColumn": 46, - "lineCount": 1 - } - }, - { - "code": "reportAttributeAccessIssue", - "range": { - "startColumn": 30, - "endColumn": 46, - "lineCount": 1 - } - }, { "code": "reportUnknownMemberType", "range": { @@ -7427,22 +7307,6 @@ "lineCount": 1 } }, - { - "code": "reportUnknownMemberType", - "range": { - "startColumn": 23, - "endColumn": 41, - "lineCount": 1 - } - }, - { - "code": "reportAttributeAccessIssue", - "range": { - "startColumn": 25, - "endColumn": 41, - "lineCount": 1 - } - }, { "code": "reportAny", "range": { @@ -7990,34 +7854,18 @@ } }, { - "code": "reportUnreachable", + "code": "reportOptionalMemberAccess", "range": { - "startColumn": 4, - "endColumn": 18, - "lineCount": 16 - } - }, - { - "code": "reportUnreachable", - "range": { - "startColumn": 8, - "endColumn": 14, + "startColumn": 14, + "endColumn": 15, "lineCount": 1 } }, { - "code": "reportUnreachable", - "range": { - "startColumn": 8, - "endColumn": 18, - "lineCount": 3 - } - }, - { - "code": "reportUnreachable", + "code": "reportUnusedClass", "range": { - "startColumn": 12, - "endColumn": 18, + "startColumn": 14, + "endColumn": 22, "lineCount": 1 } } @@ -8835,22 +8683,6 @@ "lineCount": 1 } }, - { - "code": "reportUnknownVariableType", - "range": { - "startColumn": 8, - "endColumn": 14, - "lineCount": 1 - } - }, - { - "code": "reportUnknownMemberType", - "range": { - "startColumn": 17, - "endColumn": 37, - "lineCount": 1 - } - }, { "code": "reportUnknownParameterType", "range": {