Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ more precise __config__ and __init__ annotations #362

Merged
merged 1 commit into from
Dec 21, 2024
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
106 changes: 96 additions & 10 deletions scipy-stubs/__config__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,116 @@
# It contains system_info results at the time of building this package.
from enum import Enum
from types import ModuleType
from typing import Final, Literal, TypedDict, overload
from typing import Final, Literal, TypedDict, TypeVar, overload, type_check_only
from typing_extensions import NotRequired

__all__ = ["show"]

_ConfigCompilerDict = TypedDict(
"_ConfigCompilerDict",
{
"name": str,
"version": str,
"linker": str,
"commands": str,
"args": NotRequired[str],
"linker args": NotRequired[str],
},
)
_ConfigCompilerFortranDict = TypedDict(
"_ConfigCompilerFortranDict",
{
"version": str,
"include directory": str,
},
)
_ConfigCompilersDict = TypedDict(
"_ConfigCompilersDict",
{
"c": _ConfigCompilerDict,
"cython": _ConfigCompilerDict,
"c++": _ConfigCompilerDict,
"fortran": _ConfigCompilerDict,
"pythran": _ConfigCompilerFortranDict,
},
)

@type_check_only
class _ConfigMachineInformationValueDict(TypedDict):
cpu: str
family: str
endian: Literal["little", "big"]
system: str

_ConfigMachineInformationDict = TypedDict(
"_ConfigMachineInformationDict",
{
"host": _ConfigMachineInformationValueDict,
"build": _ConfigMachineInformationValueDict,
"cross-compiled": bool,
},
)
_ConfigBuildDependencyDict = TypedDict(
"_ConfigBuildDependencyDict",
{
"name": str,
"found": bool,
"version": str,
"detection method": str,
"include directory": str,
"lib directory": str,
"openblas configuration": str,
"pc file directory": str,
},
)
_ConfigBuildDependencyPybind11Dict = TypedDict(
"_ConfigBuildDependencyPybind11Dict",
{
"name": Literal["pybind11"],
"version": str,
"detection method": NotRequired[str],
"include directory": str,
},
)

@type_check_only
class _ConfigBuildDependenciesDict(TypedDict):
blas: _ConfigBuildDependencyDict
lapack: _ConfigBuildDependencyDict
pybind11: _ConfigBuildDependencyPybind11Dict

@type_check_only
class _ConfigPythonInformationDict(TypedDict):
path: str
version: Literal["3.10", "3.11", "3.12", "3.13", "3.14"]

_ConfigDict = TypedDict(
"_ConfigDict",
{
"Compilers": dict[str, dict[str, str]],
"Machine Information": dict[str, dict[str, str] | bool],
"Build Dependencies": dict[str, dict[str, str | bool]],
"Python Information": dict[str, str],
"Compilers": _ConfigCompilersDict,
"Machine Information": _ConfigMachineInformationDict,
"Build Dependencies": _ConfigBuildDependenciesDict,
"Python Information": _ConfigPythonInformationDict,
},
)

_built_with_meson: Final[bool]
###

_built_with_meson: Final[bool] = ...
CONFIG: Final[_ConfigDict] = ...

class DisplayModes(Enum):
stdout = "stdout"
dicts = "dicts"

CONFIG: Final[_ConfigDict]

def _check_pyyaml() -> ModuleType: ...
#
@overload
def show(mode: Literal["stdout"] = "stdout") -> _ConfigDict: ...
def show(mode: Literal["stdout"] = "stdout") -> None: ...
@overload
def show(mode: Literal["dicts"]) -> _ConfigDict: ...

#
_ConfigT = TypeVar("_ConfigT", bound=_ConfigDict)

def _cleanup(d: _ConfigT) -> _ConfigT: ...
def _check_pyyaml() -> ModuleType: ...
56 changes: 28 additions & 28 deletions scipy-stubs/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from collections.abc import Sequence
from typing import Final, Literal
from typing_extensions import LiteralString
from typing import Final, Literal, TypeAlias

from numpy import __version__ as __numpy_version__ # noqa: ICN003
from . import (
Expand Down Expand Up @@ -53,32 +52,33 @@ __all__ = [
"stats",
"test",
]
np_minversion: Final[LiteralString]
np_maxversion: Final[LiteralString]

test: Final[PytestTester]
###

submodules: Final[
Sequence[
Literal[
"cluster",
"constants",
"datasets",
"differentiate",
"fft",
"fftpack",
"integrate",
"interpolate",
"io",
"linalg",
"ndimage",
"odr",
"optimize",
"signal",
"sparse",
"spatial",
"special",
"stats",
]
]
_SubModule: TypeAlias = Literal[
"cluster",
"constants",
"datasets",
"differentiate",
"fft",
"fftpack",
"integrate",
"interpolate",
"io",
"linalg",
"ndimage",
"odr",
"optimize",
"signal",
"sparse",
"spatial",
"special",
"stats",
]

###

np_minversion: Final = "1.23.5" # undocumented
np_maxversion: Final = "2.5.0" # undocumented
test: Final[PytestTester] = ... # undocumented
submodules: Final[Sequence[_SubModule]] = ... # undocumented
Loading