diff --git a/.basedpyright/baseline.json b/.basedpyright/baseline.json index 3cafdf0..84d4ba1 100644 --- a/.basedpyright/baseline.json +++ b/.basedpyright/baseline.json @@ -25,6 +25,38 @@ "lineCount": 1 } }, + { + "code": "reportUnknownParameterType", + "range": { + "startColumn": 10, + "endColumn": 13, + "lineCount": 1 + } + }, + { + "code": "reportMissingParameterType", + "range": { + "startColumn": 10, + "endColumn": 13, + "lineCount": 1 + } + }, + { + "code": "reportUnknownMemberType", + "range": { + "startColumn": 4, + "endColumn": 15, + "lineCount": 1 + } + }, + { + "code": "reportUndefinedVariable", + "range": { + "startColumn": 37, + "endColumn": 70, + "lineCount": 1 + } + }, { "code": "reportAttributeAccessIssue", "range": { @@ -4225,46 +4257,6 @@ "lineCount": 1 } }, - { - "code": "reportUnknownParameterType", - "range": { - "startColumn": 8, - "endColumn": 27, - "lineCount": 1 - } - }, - { - "code": "reportUnknownParameterType", - "range": { - "startColumn": 34, - "endColumn": 38, - "lineCount": 1 - } - }, - { - "code": "reportMissingParameterType", - "range": { - "startColumn": 34, - "endColumn": 38, - "lineCount": 1 - } - }, - { - "code": "reportUnknownVariableType", - "range": { - "startColumn": 15, - "endColumn": 19, - "lineCount": 1 - } - }, - { - "code": "reportUnknownVariableType", - "range": { - "startColumn": 4, - "endColumn": 13, - "lineCount": 1 - } - }, { "code": "reportUnannotatedClassAttribute", "range": { @@ -15135,6 +15127,14 @@ "lineCount": 1 } }, + { + "code": "reportUnknownVariableType", + "range": { + "startColumn": 4, + "endColumn": 16, + "lineCount": 1 + } + }, { "code": "reportUnknownArgumentType", "range": { @@ -15945,6 +15945,14 @@ "lineCount": 1 } }, + { + "code": "reportUnknownParameterType", + "range": { + "startColumn": 4, + "endColumn": 12, + "lineCount": 1 + } + }, { "code": "reportUnknownParameterType", "range": { @@ -15993,6 +16001,14 @@ "lineCount": 1 } }, + { + "code": "reportUnknownVariableType", + "range": { + "startColumn": 4, + "endColumn": 10, + "lineCount": 1 + } + }, { "code": "reportUnknownArgumentType", "range": { @@ -16016,6 +16032,14 @@ "endColumn": 16, "lineCount": 1 } + }, + { + "code": "reportUnknownVariableType", + "range": { + "startColumn": 11, + "endColumn": 17, + "lineCount": 1 + } } ], "./pymbolic/mapper/__init__.py": [ @@ -31971,6 +31995,14 @@ "lineCount": 1 } }, + { + "code": "reportUnknownVariableType", + "range": { + "startColumn": 4, + "endColumn": 5, + "lineCount": 1 + } + }, { "code": "reportUnknownVariableType", "range": { @@ -32467,14 +32499,6 @@ "lineCount": 1 } }, - { - "code": "reportMissingTypeStubs", - "range": { - "startColumn": 11, - "endColumn": 23, - "lineCount": 1 - } - }, { "code": "reportAny", "range": { diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 016b75c..ef50eef 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -69,7 +69,7 @@ jobs: . ./ci-support-v0 build_py_project_in_venv pip install -e .[test] - python -m pip install numpy pexpect sympy scipy + python -m pip install numpy pexpect sympy scipy scipy-stubs python -m pip install basedpyright basedpyright diff --git a/doc/conf.py b/doc/conf.py index 59cc0b8..51dedec 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -2,8 +2,7 @@ from urllib.request import urlopen -_conf_url = \ - "https://raw.githubusercontent.com/inducer/sphinxconfig/main/sphinxconfig.py" +_conf_url = "https://raw.githubusercontent.com/inducer/sphinxconfig/main/sphinxconfig.py" with urlopen(_conf_url) as _inf: exec(compile(_inf.read(), _conf_url, "exec"), globals()) @@ -28,28 +27,48 @@ "constantdict": ("https://matthiasdiener.github.io/constantdict/", None) } + autodoc_type_aliases = { "Expression": "Expression", "ArithmeticExpression": "ArithmeticExpression", } - -import sys - - nitpick_ignore_regex = [ - # Avoids this error in pymbolic.typing. - # :1: WARNING: py:class reference target not found: ExpressionNode [ref.class] # noqa: E501 - # Understandable, because typing can't import primitives, which would be needed - # to resolve the reference. - ["py:class", r"ExpressionNode"], - ["py:class", r"_Expression"], - ["py:class", r"p\.AlgebraicLeaf"], - # Sphinx started complaining about these in 8.2.1(-ish) # -AK, 2025-02-24 ["py:class", r"TypeAliasForwardRef"], ] +sphinxconfig_missing_reference_aliases = { + # numpy + "NDArray": "obj:numpy.typing.NDArray", + "DTypeLike": "obj:numpy.typing.DTypeLike", + "np.inexact": "class:numpy.inexact", + "np.generic": "class:numpy.generic", + # pytools typing + "T": "class:pytools.T", + "ShapeT": "class:pytools.obj_array.ShapeT", + "ObjectArray": "class:pytools.obj_array.ObjectArray", + "ObjectArray1D": "class:pytools.obj_array.ObjectArray", + # pymbolic typing + "ArithmeticExpression": "data:pymbolic.typing.ArithmeticExpression", + "Expression": "data:pymbolic.typing.Expression", + "p.AlgebraicLeaf": "class:pymbolic.primitives.AlgebraicLeaf", + "ExpressionNode": "class:pymbolic.primitives.ExpressionNode", + "_Expression": "class:pymbolic.primitives.ExpressionNode", + "Lookup": "class:pymbolic.primitives.Lookup", + "LogicalAnd": "class:pymbolic.primitives.LogicalAnd", + "LogicalOr": "class:pymbolic.primitives.LogicalOr", + "LogicalNot": "class:pymbolic.primitives.LogicalNot", + "Comparison": "class:pymbolic.primitives.Comparison", +} + + +def setup(app): + app.connect("missing-reference", process_autodoc_missing_reference) # noqa: F821 + + +import sys + sys._BUILDING_SPHINX_DOCS = True diff --git a/pymbolic/algorithm.py b/pymbolic/algorithm.py index 068a41b..48e691c 100644 --- a/pymbolic/algorithm.py +++ b/pymbolic/algorithm.py @@ -15,20 +15,6 @@ .. class:: _CanMultiplyT A type variable for a type that supports multiplication. - -.. class:: NDArray - - See :data:`numpy.typing.NDArray`. - -.. currentmodule:: np - -.. class:: generic - - See :class:`numpy.generic`. - -.. class:: inexact - - See :class:`numpy.inexact`. """ from __future__ import annotations diff --git a/pymbolic/geometric_algebra/__init__.py b/pymbolic/geometric_algebra/__init__.py index 6fae254..3ebeb79 100644 --- a/pymbolic/geometric_algebra/__init__.py +++ b/pymbolic/geometric_algebra/__init__.py @@ -140,13 +140,6 @@ .. literalinclude:: ../test/test_pymbolic.py :start-after: START_GA_TEST :end-before: END_GA_TEST - -References ----------- - -.. class:: DTypeLike - - See :data:`numpy.typing.DTypeLike`. """ diff --git a/pymbolic/primitives.py b/pymbolic/primitives.py index 0e2616c..33f3497 100644 --- a/pymbolic/primitives.py +++ b/pymbolic/primitives.py @@ -37,7 +37,6 @@ NoReturn, Protocol, TypeAlias, - TypeVar, cast, overload, ) @@ -47,7 +46,7 @@ from typing_extensions import Self, TypeIs, dataclass_transform import pytools.obj_array as obj_array -from pytools import module_getattr_for_deprecations, ndindex +from pytools import T, module_getattr_for_deprecations, ndindex from pytools.obj_array import ( ObjectArray, ObjectArray1D, @@ -315,75 +314,6 @@ def _have_numpy() -> bool: .. autoclass:: EmptyOK .. autoclass:: _AttributeLookupCreator - -References ----------- - -.. class:: ObjectArray - - See :class:`pytools.obj_array.ObjectArray`. - -.. class:: ObjectArray1D - - See :class:`pytools.obj_array.ObjectArray`. - -.. class:: ShapeT - - See :class:`pytools.obj_array.ShapeT`. - -.. class:: DataclassInstance - - An instance of a :func:`~dataclasses.dataclass`. - -.. class:: ArithmeticExpression - - See :class:`pymbolic.ArithmeticExpression` - -.. class:: _T - - A type variable. - -.. currentmodule:: numpy - -.. class:: bool_ - - Deprecated alias for :class:`numpy.bool`. - -.. currentmodule:: typing_extensions - -.. class:: TypeIs - - See :data:`typing_extensions.TypeIs`. - -.. class:: Variable - - See :class:`pymbolic.Variable`. - -.. class:: Expression - - See :data:`pymbolic.typing.Expression`. - -.. currentmodule:: pymbolic - -.. class:: Comparison - - See :class:`pymbolic.primitives.Comparison`. - -.. class:: LogicalNot - - See :class:`pymbolic.primitives.LogicalNot`. - -.. class:: LogicalAnd - - See :class:`pymbolic.primitives.LogicalAnd`. - -.. class:: LogicalOr - - See :class:`pymbolic.primitives.LogicalOr`. - -.. class:: Lookup - - See :class:`pymbolic.primitives.Lookup`. """ @@ -1117,15 +1047,12 @@ def {cls.__name__}_setstate(self, state): # }}} -_T = TypeVar("_T") - - @dataclass_transform(frozen_default=True, field_specifiers=(dataclasses.field,)) def expr_dataclass( init: bool = True, eq: bool = True, hash: bool = True, - ) -> Callable[[type[_T]], type[_T]]: + ) -> Callable[[type[T]], type[T]]: r"""A class decorator that makes the class a :func:`~dataclasses.dataclass` while also adding functionality needed for :class:`ExpressionNode`. Specifically, it adds cached hashing, equality comparisons @@ -1141,7 +1068,7 @@ def expr_dataclass( .. versionadded:: 2024.1 """ - def map_cls(cls: type[_T]) -> type[_T]: + def map_cls(cls: type[T]) -> type[T]: # Frozen dataclasses (empirically) have a ~20% speed penalty in pymbolic, # and their frozen-ness is arguably a debug feature.