Skip to content

Commit

Permalink
👽️ fft[pack]: fix new stubtest errors (#336)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorenham authored Dec 16, 2024
2 parents 5f92ae2 + 848fd90 commit 9673996
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 25 deletions.
24 changes: 9 additions & 15 deletions .mypyignore
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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?)?
Expand Down
7 changes: 0 additions & 7 deletions .mypyignore-todo
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
5 changes: 4 additions & 1 deletion scipy-stubs/_lib/_ccallback.pyi
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -104,6 +104,9 @@ ffi: Literal[False] | None

# public api

@final
class PyCFuncPtr(_CFuncPtr): ...

@final
class CData: ...

Expand Down
4 changes: 4 additions & 0 deletions scipy-stubs/fft/_basic_backend.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Final

from ._basic import (
fft as fft,
fft2 as fft2,
Expand All @@ -18,3 +20,5 @@ from ._basic import (
rfft2 as rfft2,
rfftn as rfftn,
)

complex_funcs: Final = {"fft", "ifft", "fftn", "ifftn", "hfft", "irfft", "irfftn"}
3 changes: 1 addition & 2 deletions scipy-stubs/fftpack/_pseudo_diffs.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from _thread import _local as _Cache # seriously, typeshed?
from typing import TypeAlias, overload

import numpy as np
Expand All @@ -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}

###

#
Expand Down

0 comments on commit 9673996

Please sign in to comment.