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
16 changes: 8 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,13 @@ jobs:
- name: ruff format --check
run: uv run ruff format --check

- name: basedpyright (numpy-stubs)
- name: basedpyright
run: >
uv run basedpyright
test/
tool/
src/_numtype/
src/numtype/
src/numpy-stubs/_core/__init__.pyi
src/numpy-stubs/_core/_asarray.pyi
src/numpy-stubs/_core/_internal.pyi
Expand Down Expand Up @@ -100,9 +104,11 @@ jobs:
src/numpy-stubs/matlib.pyi
src/numpy-stubs/version.pyi

- name: mypy (numpy-stubs)
- name: mypy (src)
run: >
uv run test/mypy.py
src/_numtype/
src/numtype/
src/numpy-stubs/_core/__init__.pyi
src/numpy-stubs/_core/_asarray.pyi
src/numpy-stubs/_core/_internal.pyi
Expand Down Expand Up @@ -161,14 +167,8 @@ jobs:
src/numpy-stubs/matlib.pyi
src/numpy-stubs/version.pyi

- name: basedpyright (test)
run: uv run basedpyright test

- name: mypy (test)
run: uv run test/mypy.py

- name: basedpyright (tool)
run: uv run basedpyright tool

- name: pytest
run: uv run pytest
18 changes: 12 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ classifiers = [
packages = [
{include = "src/numpy-stubs"},
{include = "src/numtype"},
{include = "src/_numtype"},
]
requires-python = ">=3.10"
dependencies = []
Expand Down Expand Up @@ -56,7 +57,11 @@ dev = [


[tool.hatch.build]
packages = ["src/numpy-stubs", "src/numtype"]
packages = [
"src/_numtype",
"src/numtype",
"src/numpy-stubs",
]

[tool.hatch.build.targets.sdist]
exclude = [
Expand Down Expand Up @@ -101,10 +106,10 @@ warn_unreachable = false

[tool.pyright]
include = [
"src/numpy-stubs",
"src/_numtype",
"src/numtype",
"test/runtime",
"test/static",
"src/numpy-stubs",
"test",
"tool",
]
ignore = [".venv", "test/.venv"]
Expand Down Expand Up @@ -142,7 +147,7 @@ strictGenericNarrowing = true


[tool.ruff]
src = ["src/numpy-stubs", "src/numtype", "test", "tool"]
src = ["src", "test", "tool"]
extend-exclude = [".git", ".mypy_cache", ".tox", ".venv"]
force-exclude = true
# https://typing.readthedocs.io/en/latest/guides/writing_stubs.html#maximum-line-length
Expand Down Expand Up @@ -193,12 +198,13 @@ preview = true
"numpy" = "np"
"numpy.typing" = "npt"
"numtype" = "nt"
"_numtype" = "_nt"

[tool.ruff.lint.isort]
case-sensitive = true
combine-as-imports = true
extra-standard-library = ["_typeshed", "typing_extensions"]
known-first-party = ["numpy"]
known-first-party = ["numpy", "numtype", "_numtype"]
split-on-trailing-comma = true

[tool.ruff.lint.pydocstyle]
Expand Down
482 changes: 482 additions & 0 deletions src/_numtype/__init__.pyi

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions src/_numtype/ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
extend = "../../pyproject.toml"
line-length = 130

[lint]
extend-ignore = [
"A", # flake8-builtins
"PYI064", # flake8-pyi: redundant-final-literal
"PLR2044", # pylint/R: empty-comment
"PLR6301", # pylint/R: no-self-use
"PLW3201", # pylint/W: bad-dunder-method-name
]
2 changes: 1 addition & 1 deletion test/runtime/test_numtype.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import numtype as nt
import pytest

import numpy as np
import numpy.typing as npt
import numtype as nt


def test_superset() -> None:
Expand Down
2 changes: 1 addition & 1 deletion test/static/accept/comparisons.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ c: Final = 1j
f: Final = 1.0
i: Final = 1

AR: Final = np.array([0], dtype=np.int64) # noqa: PYI015
AR: Final = np.array([0], dtype=np.int64)
AR.setflags(write=False)

SEQ: Final = (0, 1, 2, 3, 4)
Expand Down
1 change: 1 addition & 0 deletions test/static/ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ extend = "../ruff.toml"
[lint]
extend-ignore = [
"PTH", # flake8-use-pathlib
"PYI015", # flake8-pyi: assignment-default-in-stub
"PYI017", # flake8-pyi: complex-assignment-in-stub
"SLF001", # flake8-self: private-member-access
]
74 changes: 74 additions & 0 deletions test/static/test__numtype.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# ruff: noqa: PYI042, UP018
from typing import TypeAlias
from typing_extensions import TypeVar

import _numtype as _nt
import numpy as np

_SCT = TypeVar("_SCT", bound=np.generic)
_0D: TypeAlias = np.ndarray[tuple[()], np.dtype[_SCT]]
_1D: TypeAlias = np.ndarray[tuple[int], np.dtype[_SCT]]
_2D: TypeAlias = np.ndarray[tuple[int, int], np.dtype[_SCT]]
_3D: TypeAlias = np.ndarray[tuple[int, int, int], np.dtype[_SCT]]
_ND: TypeAlias = np.ndarray[tuple[int, ...], np.dtype[_SCT]]

b_: bool
i_: int
f_: float
c_: complex
S_: bytes
U_: str
O_: object

b1: np.bool
b1_0d: _0D[np.bool]
b1_1d: _1D[np.bool]
b1_2d: _2D[np.bool]
b1_3d: _3D[np.bool]
b1_nd: _ND[np.bool]
like_bool_0d: bool | np.bool | _0D[np.bool]
like_bool_1d: list[bool | np.bool] | _1D[np.bool]
like_bool_2d: list[list[bool | np.bool]] | list[_1D[np.bool]] | _2D[np.bool]
like_bool_3d: list[list[list[bool | np.bool]]] | list[_2D[np.bool]] | list[list[_1D[np.bool]]] | _3D[np.bool]
like_bool_nd: list[list[list[list[bool | np.bool]]]] | list[_2D[np.bool]] | _ND[np.bool]

bool_0d_accept: _nt.As0D_bool = like_bool_0d
bool_0d_reject_sc: _nt.As0D_bool = f_ # type: ignore[assignment] # pyright: ignore[reportAssignmentType]
bool_0d_reject_1d: _nt.As0D_bool = b1_1d # type: ignore[assignment] # pyright: ignore[reportAssignmentType]
bool_0d_reject_2d: _nt.As0D_bool = b1_2d # type: ignore[assignment] # pyright: ignore[reportAssignmentType]
bool_0d_reject_3d: _nt.As0D_bool = b1_3d # type: ignore[assignment] # pyright: ignore[reportAssignmentType]
bool_0d_reject_nd: _nt.As0D_bool = b1_nd # type: ignore[assignment] # pyright: ignore[reportAssignmentType]

bool_1d_accept: _nt.As1D_bool = like_bool_1d
bool_1d_reject_sc: _nt.As1D_bool = [f_] # type: ignore[list-item] # pyright: ignore[reportAssignmentType]
bool_1d_reject_0d: _nt.As1D_bool = b1 # type: ignore[assignment] # pyright: ignore[reportAssignmentType]
bool_1d_reject_2d: _nt.As1D_bool = b1_2d # type: ignore[assignment] # pyright: ignore[reportAssignmentType]
bool_1d_reject_3d: _nt.As1D_bool = b1_3d # type: ignore[assignment] # pyright: ignore[reportAssignmentType]
bool_1d_reject_nd: _nt.As1D_bool = b1_nd # type: ignore[assignment] # pyright: ignore[reportAssignmentType]

bool_2d_accept: _nt.As2D_bool = like_bool_2d
bool_2d_reject_sc: _nt.As2D_bool = [[f_]] # type: ignore[list-item] # pyright: ignore[reportAssignmentType]
bool_2d_reject_0d: _nt.As2D_bool = b1 # type: ignore[assignment] # pyright: ignore[reportAssignmentType]
bool_2d_reject_1d: _nt.As2D_bool = b1_1d # type: ignore[assignment] # pyright: ignore[reportAssignmentType]
bool_2d_reject_3d: _nt.As2D_bool = b1_3d # type: ignore[assignment] # pyright: ignore[reportAssignmentType]
bool_2d_reject_nd: _nt.As2D_bool = b1_nd # type: ignore[assignment] # pyright: ignore[reportAssignmentType]

bool_3d_accept: _nt.As3D_bool = like_bool_3d
bool_3d_reject_sc: _nt.As3D_bool = [[[f_]]] # type: ignore[list-item] # pyright: ignore[reportAssignmentType]
bool_3d_reject_0d: _nt.As3D_bool = b1 # type: ignore[assignment] # pyright: ignore[reportAssignmentType]
bool_3d_reject_1d: _nt.As3D_bool = b1_1d # type: ignore[assignment] # pyright: ignore[reportAssignmentType]
bool_3d_reject_2d: _nt.As3D_bool = b1_2d # type: ignore[assignment] # pyright: ignore[reportAssignmentType]
bool_3d_reject_nd: _nt.As3D_bool = b1_nd # type: ignore[assignment] # pyright: ignore[reportAssignmentType]

bool_nd_accept_0d: _nt.AsND_bool = b1_0d
bool_nd_accept_1d: _nt.AsND_bool = like_bool_1d
bool_nd_accept_2d: _nt.AsND_bool = like_bool_2d
bool_nd_accept_3d: _nt.AsND_bool = like_bool_3d
bool_nd_reject_0d: _nt.AsND_bool = b1 # type: ignore[assignment] # pyright: ignore[reportAssignmentType]
bool_nd_reject_1d_sc: _nt.AsND_bool = [f_] # type: ignore[assignment] # pyright: ignore[reportAssignmentType]
bool_nd_reject_2d_sc: _nt.AsND_bool = [[f_]] # type: ignore[assignment] # pyright: ignore[reportAssignmentType]
bool_nd_reject_3d_sc: _nt.AsND_bool = [[[f_]]] # type: ignore[assignment] # pyright: ignore[reportAssignmentType]

# TODO: repeat for all the other `_As` types
# TODO: repeat for the `_To` types
# TODO: realize that I'm not a factory worker => codegen it (parametrized pytests)