Skip to content

Commit

Permalink
Merge pull request #76 from jorenham/stubtest/scipy._lib
Browse files Browse the repository at this point in the history
`scipy._lib`
  • Loading branch information
jorenham authored Oct 11, 2024
2 parents c7f4a66 + fea097e commit 03e31d6
Show file tree
Hide file tree
Showing 25 changed files with 473 additions and 418 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ jobs:
- name: typecheck (partial)
run: |
targets=(
"_lib"
"cluster"
"constants"
"datasets"
Expand All @@ -73,7 +74,7 @@ jobs:
fail-fast: false
matrix:
module: [
# "scipy._lib",
"scipy._lib",
"scipy.cluster",
"scipy.constants",
"scipy.datasets",
Expand Down
42 changes: 21 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,27 +74,27 @@ pip install scipy-stubs

## Development Status

| Package | `ruff`/`flake8-pyi` | `stubtest` | `based{mypy,pyright}` | completeness |
| :------------------ | :-----------------: | :----------------: | :-------------------: | :--------------------: |
| `scipy._lib` | :heavy_check_mark: | :x: | :x: | :waxing_crescent_moon: |
| `scipy.cluster` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :full_moon: |
| `scipy.constants` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :full_moon: |
| `scipy.datasets` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :full_moon: |
| `scipy.fft` | :heavy_check_mark: | :heavy_check_mark: | :x: | :waxing_crescent_moon: |
| `scipy.fftpack` | :heavy_check_mark: | :heavy_check_mark: | :x: | :waxing_crescent_moon: |
| `scipy.integrate` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :waxing_gibbous_moon: |
| `scipy.interpolate` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :first_quarter_moon: |
| `scipy.io` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :full_moon: |
| `scipy.linalg` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :waxing_gibbous_moon: |
| ~`scipy.misc`~ | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :full_moon: |
| `scipy.ndimage` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :full_moon: |
| `scipy.odr` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :waxing_crescent_moon: |
| `scipy.optimize` | :heavy_check_mark: | :heavy_check_mark: | :x: | :first_quarter_moon: |
| `scipy.signal` | :heavy_check_mark: | :x: | :x: | :new_moon: |
| `scipy.sparse` | :heavy_check_mark: | :x: | :x: | :waxing_crescent_moon: |
| `scipy.spatial` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :waxing_gibbous_moon: |
| `scipy.special` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :first_quarter_moon: |
| `scipy.stats` | :heavy_check_mark: | :x: | :x: | :first_quarter_moon: |
| `scipy._` | `ruff` & `flake8-pyi` | `stubtest` | `basedmypy` | `basedpyright` | phase |
| :------------ | :-------------------: | :----------------: | :----------------: | :----------------: | :--------------------: |
| `_lib` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :waxing_gibbous_moon: |
| `cluster` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :full_moon: |
| `constants` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :full_moon_with_face: |
| `datasets` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :full_moon_with_face: |
| `fft` | :heavy_check_mark: | :heavy_check_mark: | :x: | :x: | :waxing_crescent_moon: |
| `fftpack` | :heavy_check_mark: | :heavy_check_mark: | :x: | :x: | :waxing_crescent_moon: |
| `integrate` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :waxing_gibbous_moon: |
| `interpolate` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :first_quarter_moon: |
| `io` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :full_moon: |
| `linalg` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :waxing_gibbous_moon: |
| ~`misc`~ | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :full_moon: |
| `ndimage` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :full_moon: |
| `odr` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :waxing_crescent_moon: |
| `optimize` | :heavy_check_mark: | :heavy_check_mark: | :x: | :x: | :first_quarter_moon: |
| `signal` | :heavy_check_mark: | :x: | :x: | :x: | :new_moon: |
| `sparse` | :heavy_check_mark: | :x: | :x: | :x: | :waxing_crescent_moon: |
| `spatial` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :waxing_gibbous_moon: |
| `special` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :first_quarter_moon: |
| `stats` | :heavy_check_mark: | :x: | :x: | :x: | :first_quarter_moon: |

## Version Compatibility

Expand Down
27 changes: 26 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ version = "1.14.1.0.dev0"

[tool.poetry.dependencies]
python = "^3.10.1"
numpy = ">=1.25"
scipy = ">=1.14.1"
optype = "^0.6.1"
types-cffi = ">=1.16.0"

[tool.poetry.group.lint.dependencies]
basedmypy = "^2.6.0"
Expand Down
33 changes: 26 additions & 7 deletions scipy-stubs/_lib/_array_api.pyi
Original file line number Diff line number Diff line change
@@ -1,19 +1,38 @@
from types import ModuleType
from typing import Any, Literal
from typing import Literal, Protocol, TypeAlias, TypeVar, type_check_only

from scipy._lib.array_api_compat import device, size
from scipy._typing import Untyped
import numpy.typing as npt

__all__ = ["_asarray", "array_namespace", "device", "size"]

_DeviceT_co = TypeVar("_DeviceT_co", covariant=True)

# TODO: To be changed to a `Protocol` (once they learn about Python typing, so don't get your hopes up)
# https://github.com/data-apis/array-api/pull/589
Array: TypeAlias = object
ArrayLike: TypeAlias = Array | npt.ArrayLike
_DType: TypeAlias = object | npt.DTypeLike

@type_check_only
class _HasDevice(Protocol[_DeviceT_co]):
@property
def device(self, /) -> _DeviceT_co: ...

@type_check_only
class _HasShape(Protocol):
@property
def shape(self, /) -> tuple[int, ...]: ...

def _asarray(
array: Untyped,
dtype: Any = None,
array: ArrayLike,
dtype: _DType = None,
order: Literal["K", "A", "C", "F"] | None = None,
copy: bool | None = None,
*,
xp: ModuleType | None = None,
check_finite: bool = False,
subok: bool = False,
) -> Untyped: ...
def array_namespace(*arrays: Untyped) -> ModuleType: ...
) -> Array: ...
def array_namespace(*arrays: Array) -> ModuleType: ...
def device(x: _HasDevice[_DeviceT_co], /) -> _DeviceT_co: ...
def size(x: _HasShape) -> int: ...
Empty file removed scipy-stubs/_lib/_boost_utils.pyi
Empty file.
17 changes: 7 additions & 10 deletions scipy-stubs/_lib/_ccallback.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,19 @@ from types import ModuleType
from typing import Generic, Literal, NoReturn, TypeAlias
from typing_extensions import CapsuleType, Never, Self, TypeVar, override

from cffi.model import FunctionPtrType as _CFFIFuncP, PointerType as _CFFIVoidP
from scipy._typing import Untyped

__all__ = ["LowLevelCallable"]

# TODO: add `types-cffi` as dependency
_CFFIFuncP: TypeAlias = object
_CFFIVoidP: TypeAlias = object
ffi: Literal[False] | None

class CData: ...

_Function: TypeAlias = CapsuleType | PyCFuncPtr | _CFFIFuncP | CData
_UserData: TypeAlias = CapsuleType | ct.c_void_p | _CFFIVoidP

_FuncT_co = TypeVar("_FuncT_co", bound=_Function, covariant=True, default=_Function)
_DataT_co = TypeVar("_DataT_co", bound=_UserData | None, covariant=True, default=_UserData)

ffi: Literal[False] | None

class CData: ...

class LowLevelCallable(tuple[CapsuleType, _FuncT_co, _DataT_co], Generic[_FuncT_co, _DataT_co]):
@property
def function(self, /) -> _FuncT_co: ...
Expand All @@ -42,6 +38,7 @@ class LowLevelCallable(tuple[CapsuleType, _FuncT_co, _DataT_co], Generic[_FuncT_
user_data: _UserData | None = None,
signature: str | None = None,
) -> Self: ...
# NOTE: __getitem__ will raise a ValueError

# NOTE: `__getitem__` will always raise a `ValueError`
@override
def __getitem__(self, idx: Never, /) -> NoReturn: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
33 changes: 20 additions & 13 deletions scipy-stubs/_lib/_disjoint_set.pyi
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
from scipy._typing import Untyped
from collections.abc import Iterator
from typing import Generic
from typing_extensions import TypeVar

class DisjointSet:
import optype as op

_T = TypeVar("_T", bound=op.CanHash, default=object)

class DisjointSet(Generic[_T]):
n_subsets: int
def __init__(self, elements: Untyped | None = None): ...
def __iter__(self) -> Untyped: ...
def __len__(self) -> int: ...
def __contains__(self, x) -> bool: ...
def __getitem__(self, x) -> Untyped: ...
def add(self, x): ...
def merge(self, x, y) -> Untyped: ...
def connected(self, x, y) -> Untyped: ...
def subset(self, x) -> Untyped: ...
def subset_size(self, x) -> Untyped: ...
def subsets(self) -> Untyped: ...

def __init__(self, /, elements: _T | None = None) -> None: ...
def __iter__(self, /) -> Iterator[_T]: ...
def __len__(self, /) -> int: ...
def __contains__(self, x: object, /) -> bool: ...
def __getitem__(self, x: _T, /) -> int: ...
def add(self, /, x: _T) -> None: ...
def merge(self, /, x: _T, y: _T) -> bool: ...
def connected(self, /, x: _T, y: _T) -> bool: ...
def subset(self, /, x: _T) -> set[_T]: ...
def subset_size(self, /, x: _T) -> int: ...
def subsets(self, /) -> list[set[_T]]: ...
76 changes: 34 additions & 42 deletions scipy-stubs/_lib/_docscrape.pyi
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
from collections.abc import Callable, Mapping, Sequence
from types import ModuleType
from typing import Any, ClassVar, Final, Literal, NamedTuple, TypeAlias
from typing_extensions import LiteralString, override
from typing import ClassVar, Final, Generic, Literal, NamedTuple, TypeAlias
from typing_extensions import TypeVar, override

import optype as op
from scipy._typing import Untyped, UntypedCallable

_SectionKey: TypeAlias = LiteralString
_FT = TypeVar("_FT", bound=Callable[..., object], default=Callable[..., object])
_SectionValue: TypeAlias = str | list[str] | dict[str, list[str]]

class ParseError(Exception): ...

class Parameter(NamedTuple):
name: str
type: str
desc: str

class Reader:
def __init__(self, /, data: str | list[str]) -> None: ...
def __getitem__(self, n: op.CanIndex, /) -> str: ...
Expand All @@ -22,65 +27,52 @@ class Reader:
def peek(self, n: int = 0) -> str: ...
def is_empty(self) -> bool: ...

class ParseError(Exception): ...

class Parameter(NamedTuple):
name: str
type: str
desc: str

class NumpyDocString(Mapping[_SectionKey, _SectionValue]):
class NumpyDocString(Mapping[str, _SectionValue]):
empty_description: ClassVar[str] = ".."
sections: ClassVar[dict[_SectionKey, _SectionValue]]
def __init__(self, /, docstring: str, config: dict[str, Any] | None = None) -> None: ...
sections: ClassVar[dict[str, _SectionValue]]
def __init__(self, /, docstring: str, config: dict[str, object] = {}) -> None: ...
@override
def __getitem__(self, key: _SectionKey, /) -> _SectionValue: ...
def __setitem__(self, key: _SectionKey, val: _SectionValue, /) -> None: ...
@override
def __iter__(self, /) -> op.CanIterSelf[_SectionKey]: ...
def __str__(self, /, func_role: str = "") -> str: ...
@override
def __len__(self, /) -> int: ...
@override
def __iter__(self, /) -> op.CanIterSelf[str]: ...
@override
def __getitem__(self, key: str, /) -> _SectionValue: ...
def __setitem__(self, key: str, val: _SectionValue, /) -> None: ...

class FunctionDoc(NumpyDocString):
class FunctionDoc(NumpyDocString, Generic[_FT]):
def __init__(
self,
/,
func: UntypedCallable,
func: _FT,
role: Literal["func", "meth"] = "func",
doc: str | None = None,
config: dict[str, Any] | None = None,
config: dict[str, object] = {},
) -> None: ...
def get_func(self) -> UntypedCallable: ...

class ObjDoc(NumpyDocString):
def __init__(self, /, obj: object, doc: str | None = None, config: dict[str, Any] | None = None) -> None: ...
@override
def __str__(self, /) -> str: ... # type: ignore[override] # noqa: PYI029 # pyright: ignore[reportIncompatibleMethodOverride]
def get_func(self, /) -> _FT: ...

class ClassDoc(NumpyDocString):
extra_public_methods: ClassVar[Sequence[str]]
show_inherited_members: Final[bool]

@property
def methods(self) -> list[str]: ...
@property
def properties(self) -> list[str]: ...
def __init__(
self,
/,
cls: type,
doc: str | None = None,
modulename: str = "",
func_doc: type[FunctionDoc] = ...,
config: Untyped | None = None,
# NOTE: we can't set this to `type[FunctionDoc]` because of a mypy bug
func_doc: type = ...,
config: dict[str, object] = {},
) -> None: ...
@property
def methods(self) -> list[str]: ...
@property
def properties(self) -> list[str]: ...

def strip_blank_lines(l: list[str]) -> list[str]: ...
def indent(str: str | None, indent: int = 4) -> str: ...
def dedent_lines(lines: op.CanIter[op.CanIterSelf[str]]) -> str: ...
def get_doc_object(
obj: type | ModuleType | Callable[..., object] | object,
what: Literal["class", "module", "function", "object"] | None = None,
doc: str | None = None,
config: dict[str, Any] | None = None,
class_doc: type[ClassDoc] = ...,
func_doc: type[FunctionDoc] = ...,
obj_doc: type[ObjDoc] = ...,
) -> NumpyDocString: ...
def header(text: str, style: str = "-") -> str: ...
15 changes: 9 additions & 6 deletions scipy-stubs/_lib/_gcutils.pyi
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
from collections.abc import Generator
from contextlib import _GeneratorContextManager
from collections.abc import Callable
from typing import Final, ParamSpec, TypeVar

from scipy._typing import Untyped
_T = TypeVar("_T")
_Tss = ParamSpec("_Tss")

IS_PYPY: Untyped
IS_PYPY: Final[bool] = ...

class ReferenceError(AssertionError): ...

def set_gc_state(state): ...
def gc_state(state) -> Generator[None, None, None]: ...
def assert_deallocated(func, *args, **kwargs) -> Generator[Untyped, None, None]: ...
def set_gc_state(state: bool) -> None: ...
def gc_state(state: bool) -> _GeneratorContextManager[None]: ...
def assert_deallocated(func: Callable[_Tss, _T], *args: _Tss.args, **kwargs: _Tss.kwargs) -> _GeneratorContextManager[_T]: ...
Empty file removed scipy-stubs/_lib/_highs_utils.pyi
Empty file.
Loading

0 comments on commit 03e31d6

Please sign in to comment.