From 848fd909f34feb73239e201dade4eb63fac1b71e Mon Sep 17 00:00:00 2001 From: jorenham Date: Mon, 16 Dec 2024 18:51:25 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=BD=EF=B8=8F=20`fft[pack]`:=20fix=20ne?= =?UTF-8?q?w=20stubtest=20errors?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .mypyignore | 24 +++++++++--------------- .mypyignore-todo | 7 ------- scipy-stubs/_lib/_ccallback.pyi | 5 ++++- scipy-stubs/fft/_basic_backend.pyi | 4 ++++ scipy-stubs/fftpack/_pseudo_diffs.pyi | 3 +-- 5 files changed, 18 insertions(+), 25 deletions(-) diff --git a/.mypyignore b/.mypyignore index 25691ca1..2d44636f 100644 --- a/.mypyignore +++ b/.mypyignore @@ -1,38 +1,33 @@ # typecheck-only helper types scipy(\.\w+)?\._typing -# git submodules -scipy\._lib\.(array_api_compat|array_api_extra|cobyqa).* - -# private bundled pypocketfft library -scipy\.fft\._pocketfft\..* - # internal scipy testing code scipy\.conftest scipy\.((_|\w)+\.)+(__test__|test|tests(\..+)?) +# git submodules and bundled 3rd party libs +scipy\._lib\.(array_api_compat|array_api_extra|cobyqa).* +scipy\.fft\._pocketfft\..* + +# numpy re-export with wrong annotations on numpy<1.24 +scipy\.fftpack\.(_?helper\.)?fftfreq + # accidental implicit exports of internal scipy machinery scipy\._lib\.decorator\.(DEF|ArgSpec|FunctionMaker|__init__|append|dispatch_on|get_init|getargspec|init|n_args) -scipy\.special\._precompute\..* +scipy\.special\._precompute\..* # TODO?? scipy\.special\.libsf_error_state -scipy\.stats\._rcont.rcont +scipy\.stats\._rcont\.rcont # omitted methods that always return `NotImplemented` or always raise scipy\.sparse\._(\w+)\._(\w+)\.__(len|i(add|mul|sub)|(i|r)(true)?div)__ # workarounds for mypy bugs -scipy\._lib\._array_api\.(Array|ArrayLike) # these exist, but in `if TYPE_CHECKING: ...` -scipy\._lib\._ccallback\.PyCFuncPtr # this exists, but under `if TYPE_CHECKING: ...` scipy\.signal\._short_time_fft\.(FFT_MODE_TYPE|PAD_TYPE) # `Literal[...] != def (*, **)` scipy\.(_lib|integrate|stats)\.((_|\w)+\.)+__replace__ # `NamedTuple` on `python >= 3.13` # stubtest doesn't understand `if sys.version_info >= _: ...` blocks -scipy\.fftpack\.helper\.fftfreq scipy\.sparse\.(\w+)\.warn -# numpy re-export with wrong annotations on numpy<1.24 -scipy\.fftpack\.(_helper\.)?fftfreq - # mypy fails recognize type-check-only ufunc subtypes as ufuncs # https://github.com/KotlinIsland/basedmypy/issues/816 scipy\.special\._basic\.digamma @@ -88,7 +83,6 @@ scipy.special.dawsn scipy.special.wofz scipy.special.wrightomega scipy.special.zetac - scipy.special.bdtr(c|i(k|n)?)? scipy.special.btdtri(a|b) scipy.special.chdtr(c|iv?)? diff --git a/.mypyignore-todo b/.mypyignore-todo index cbd4c3bf..c0d9fca3 100644 --- a/.mypyignore-todo +++ b/.mypyignore-todo @@ -1,10 +1,3 @@ -scipy\.fft\._basic_backend\.complex_funcs - -scipy\.fftpack\.(_pseudo_diffs\.)?diff -scipy\.fftpack\.(_pseudo_diffs\.)?shift -scipy\.fftpack\.(_pseudo_diffs\.)?(c|s){2}_diff -scipy\.fftpack\.(_pseudo_diffs\.)?(h|t|it)ilbert - scipy\.integrate\.(_quadrature\.)?__all__ scipy\.integrate\.(_quadrature\.)?AccuracyWarning scipy\.integrate\.(_quadrature\.)?(quadrature|romberg|romberg|simpson) diff --git a/scipy-stubs/_lib/_ccallback.pyi b/scipy-stubs/_lib/_ccallback.pyi index 9e1f60e4..926fa916 100644 --- a/scipy-stubs/_lib/_ccallback.pyi +++ b/scipy-stubs/_lib/_ccallback.pyi @@ -1,5 +1,5 @@ import ctypes as ct -from _ctypes import CFuncPtr as PyCFuncPtr +from _ctypes import CFuncPtr as _CFuncPtr from types import ModuleType from typing import ClassVar, Generic, Literal, NoReturn, Protocol, TypeAlias, final, overload, type_check_only from typing_extensions import CapsuleType as PyCapsule, Self, TypeVar, TypeVarTuple, Unpack, override @@ -104,6 +104,9 @@ ffi: Literal[False] | None # public api +@final +class PyCFuncPtr(_CFuncPtr): ... + @final class CData: ... diff --git a/scipy-stubs/fft/_basic_backend.pyi b/scipy-stubs/fft/_basic_backend.pyi index d5566562..9ba8f4f3 100644 --- a/scipy-stubs/fft/_basic_backend.pyi +++ b/scipy-stubs/fft/_basic_backend.pyi @@ -1,3 +1,5 @@ +from typing import Final + from ._basic import ( fft as fft, fft2 as fft2, @@ -18,3 +20,5 @@ from ._basic import ( rfft2 as rfft2, rfftn as rfftn, ) + +complex_funcs: Final = {"fft", "ifft", "fftn", "ifftn", "hfft", "irfft", "irfftn"} diff --git a/scipy-stubs/fftpack/_pseudo_diffs.pyi b/scipy-stubs/fftpack/_pseudo_diffs.pyi index b7490370..e5a3f55f 100644 --- a/scipy-stubs/fftpack/_pseudo_diffs.pyi +++ b/scipy-stubs/fftpack/_pseudo_diffs.pyi @@ -1,3 +1,4 @@ +from _thread import _local as _Cache # seriously, typeshed? from typing import TypeAlias, overload import numpy as np @@ -9,8 +10,6 @@ __all__ = ["cc_diff", "cs_diff", "diff", "hilbert", "ihilbert", "itilbert", "sc_ _Vec_d: TypeAlias = onp.Array1D[np.float64] _Vec_dD: TypeAlias = onp.Array1D[np.float64 | np.complex128] -_Cache: TypeAlias = dict[tuple[onp.ToFloat, ...], _Vec_d] # {n: kernel} - ### #