Skip to content

Commit

Permalink
type hints for scipy.constants
Browse files Browse the repository at this point in the history
  • Loading branch information
jorenham committed Aug 22, 2024
1 parent b3ae475 commit bf09b60
Show file tree
Hide file tree
Showing 4 changed files with 413 additions and 128 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pip install scipy-stubs
| `scipy._lib` | 1: skeleton |
| `scipy._lib._uarray` | 0: missing |
| `scipy.cluster` | 1: skeleton |
| `scipy.constants` | 1: skeleton |
| `scipy.constants` | 3: ready |
| `scipy.datasets` | 1: skeleton |
| `scipy.fft` | 1: skeleton |
| `scipy.fft._pocketfft` | 1: skeleton |
Expand Down
8 changes: 5 additions & 3 deletions scipy-stubs/constants/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from . import codata as codata, constants as constants
from . import _codata, _constants
from ._codata import *
from ._codata import physical_constants as physical_constants
from ._constants import *
from scipy._lib._testutils import PytestTester as PytestTester

__all__: list[str] = []
__all__ += _codata.__all__
__all__ += _constants.__all__
123 changes: 106 additions & 17 deletions scipy-stubs/constants/_codata.pyi
Original file line number Diff line number Diff line change
@@ -1,26 +1,115 @@
from typing import Any
from typing import Final, Literal, TypeAlias

from scipy._typing import Untyped
from typing_extensions import LiteralString

txt2002: str
txt2006: str
txt2010: str
txt2014: str
txt2018: str
physical_constants: dict[str, tuple[float, str, float]]
__all__ = ["ConstantWarning", "find", "physical_constants", "precision", "unit", "value"]

def parse_constants_2002to2014(d: str) -> dict[str, tuple[float, str, float]]: ...
def parse_constants_2018toXXXX(d: str) -> dict[str, tuple[float, str, float]]: ...
_Unit: TypeAlias = Literal[
"",
"(GeV/c^2)^-2",
"A",
"A J^-1",
"C",
"C kg^-1",
"C m",
"C m^-3",
"C m^2",
"C mol^-1",
"C^2 m^2 J^-1",
"C^3 m^3 J^-2",
"C^4 m^4 J^-3",
"C_90 mol^-1",
"E_h",
"F",
"F m^-1",
"GeV",
"GeV^-2",
"H",
"Hz",
"Hz K^-1",
"Hz T^-1",
"Hz V^-1",
"J",
"J Hz^-1",
"J Hz^-1 mol^-1",
"J K^-1",
"J T^-1",
"J T^-2",
"J m mol^-1",
"J mol^-1 K^-1",
"J s",
"K",
"K T^-1",
"MHz T^-1",
"MeV",
"MeV fm",
"MeV/c",
"N",
"N A^-2",
"Pa",
"S",
"T",
"V",
"V m^-1",
"V m^-2",
"W",
"W m^-2 K^-4",
"W m^2",
"W m^2 sr^-1",
"Wb",
"eV",
"eV Hz^-1",
"eV K^-1",
"eV T^-1",
"eV s",
"kg",
"kg m s^-1",
"kg mol^-1",
"lm W^-1",
"m",
"m K",
"m s^-1",
"m s^-2",
"m^-1",
"m^-1 K^-1",
"m^-1 T^-1",
"m^-3",
"m^2",
"m^2 s^-1",
"m^3 kg^-1 s^-2",
"m^3 mol^-1",
"mol^-1",
"ohm",
"s",
"s^-1 T^-1",
"u",
]
_Constant: TypeAlias = tuple[float, _Unit, float]
_ConstantDict: TypeAlias = dict[LiteralString, _Constant]

# public

physical_constants: Final[_ConstantDict]

class ConstantWarning(DeprecationWarning): ...

def find(sub: str | None = ..., disp: bool = ...) -> list[LiteralString] | None: ...
def value(key: str) -> float: ...
def unit(key: str) -> str: ...
def unit(key: str) -> _Unit: ...
def precision(key: str) -> float: ...
def find(sub: str | None = None, disp: bool = False) -> Any: ...

c: Untyped
mu0: Untyped
epsilon0: Untyped
exact_values: Untyped
val: Untyped
# private

txt2002: Final[str]
txt2006: Final[str]
txt2010: Final[str]
txt2014: Final[str]
txt2018: Final[str]

def parse_constants_2002to2014(d: str) -> _ConstantDict: ...
def parse_constants_2018toXXXX(d: str) -> _ConstantDict: ...

c: Final[float]
mu0: Final[float]
epsilon0: Final[float]
exact_values: Final[_ConstantDict]
Loading

0 comments on commit bf09b60

Please sign in to comment.