Skip to content

Commit

Permalink
Merge pull request #151 from oscarbenjamin/pr_pyright
Browse files Browse the repository at this point in the history
Use pyright for type-checking
  • Loading branch information
oscarbenjamin authored Nov 6, 2024
2 parents 7b1a44f + 3e39970 commit 3f3c9e8
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ set -o errexit

pre-commit run --all-files
mypy --python-version=3.12 src tests
pyright --pythonversion 3.12 src tests
sphinx-build -b html docs docs/_build
python -m xdoctest --quiet protosym
pytest --cov=protosym
Expand Down
1 change: 1 addition & 0 deletions quicktest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ fi

hatch run pre-commit:run
hatch run types:mypy-check
hatch run types:pyright-check
hatch run docs:build
hatch run test:doctest
hatch run test:coverage
1 change: 1 addition & 0 deletions requirements-all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
-r requirements-test.txt
-r requirements-docs.txt
mypy
pyright
1 change: 0 additions & 1 deletion requirements-lint.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
ruff
black
pre-commit
pre-commit-hooks
7 changes: 6 additions & 1 deletion src/protosym/core/sym.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@

from __future__ import annotations

from typing import TYPE_CHECKING as _TYPE_CHECKING
from typing import Any, Callable, Generic, Sequence, TypeVar, overload

if _TYPE_CHECKING:
from typing_extensions import Self

from weakref import WeakValueDictionary as _WeakDict

from protosym.core.atom import AtomType
Expand Down Expand Up @@ -130,7 +135,7 @@ class Sym:

rep: Tree

def __new__(cls, tree_expr: Tree) -> Sym:
def __new__(cls, tree_expr: Tree) -> Self:
"""Create a new Sym wrapping `tree_expr`.
If an equivalent Sym instance already exists then the same object will
Expand Down
2 changes: 1 addition & 1 deletion tests/core/test_sym.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def test_Sym_evaluator() -> None:
to_str[Integer[a]] = PyFunc1[int, str](str)(a)
to_str[AtomRule[a]] = AtomFunc(str)(a)
to_str[cos(a)] = PyOp1(lambda s: f"cos({s})")(a)
to_str[Add(star(a))] = PyOpN(" + ".join)(a)
to_str[Add(star(a))] = PyOpN(str(" + ").join)(a)
to_str[HeadRule(a, b)] = HeadOp(lambda f, a: f"{f}({', '.join(a)})")(a, b)

assert to_str(cos(one)) == "cos(1)"
Expand Down
2 changes: 1 addition & 1 deletion tests/test_simplecas.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def test_simplecas_to_sympy() -> None:
(cos(x), cosx_sym),
(cos(x) ** 2 + sin(x) ** 2, cosx_sym**2 + sinx_sym**2), # pyright: ignore
(cos(x) * sin(x), cosx_sym * sinx_sym), # pyright: ignore
(f(x), f_sym(x_sym)),
(f(x), f_sym(x_sym)), # pyright: ignore
]
for expr, sympy_expr in test_cases:
# XXX: Converting to SymPy and back does not in general round-trip
Expand Down

0 comments on commit 3f3c9e8

Please # to comment.