Skip to content

Add type stubs for Cython classes in pywt._extensions #846

@NiklasMueller2001

Description

@NiklasMueller2001

Currently, many public classes and functions are implemented in the Cython modules inside pywt._extensions (e.g. wavelist, Wavelet, ...). Their public API is currently documented in the pywavelet docs; however, when writing Python code that uses these functions or classes Python type checkers such as mypy or Pyright can not determine their signature and return types or even detect their existence.

Possible solution

To enable static type checking I propose to add .pyi interface files in the pywt._extensions module. I have already created a draft version that works in my locally built pywavelets installation. Please let me know if you think this would be a useful enhancement for the package.

# pywt/_extensions/_pywt.pyi

from typing import Literal, Optional

_WaveletFamily = Literal[
    "haar",
    "db",
    "sym",
    "coif",
    "bior",
    "rbio",
    "dmey",
    "gaus",
    "mexh",
    "morl",
    "cgau",
    "shan",
    "fbsp",
    "cmor",
]

_Kind = Literal["all", "continuous", "discrete"]

_Symmetry = Literal[
    "asymmetric",
    "near symmetric",
    "symmetric",
    "anti-symmetric",
    "unknown",
]

def wavelist(family: _WaveletFamily | None = ..., kind: _Kind = ...) -> list[str]: ...
def families(short: bool = ...) -> list[str]: ...

class Wavelet:
    def __init__(self, name: str, filter_bank=None): ...
    def __len__(self) -> int: ...
    @property
    def name(self) -> str: ...
    @property
    def dec_lo(self) -> list[float]: ...
    @property
    def dec_hi(self) -> list[float]: ...
    @property
    def rec_lo(self) -> list[float]: ...
    @property
    def rec_hi(self) -> list[float]: ...
    @property
    def rec_len(self) -> int: ...
    @property
    def dec_len(self) -> int: ...
    @property
    def family_number(self) -> int: ...
    @property
    def family_name(self) -> str: ...
    @property
    def short_family_name(self) -> str: ...
    @property
    def orthogonal(self) -> bool: ...
    @orthogonal.setter
    def orthogonal(self, value: bool) -> None: ...
    @property
    def biorthogonal(self) -> bool: ...
    @biorthogonal.setter
    def biorthogonal(self, value: bool) -> None: ...
    @property
    def symmetry(self) -> _Symmetry: ...
    @property
    def vanishing_moments_psi(self) -> int | None: ...
    @property
    def vanishing_moments_phi(self) -> int | None: ...
    @property
    def filter_bank(
        self,
    ) -> tuple[list[float], list[float], list[float], list[float]]: ...
    def get_filters_coeffs(
        self,
    ) -> tuple[list[float], list[float], list[float], list[float]]: ...
    @property
    def inverse_filter_bank(
        self,
    ) -> tuple[list[float], list[float], list[float], list[float]]: ...
    def get_reverse_filters_coeffs(
        self,
    ) -> tuple[list[float], list[float], list[float], list[float]]: ...

class ContinuousWavelet:
    @property
    def family_number(self) -> int: ...
    @property
    def family_name(self) -> str: ...
    @property
    def short_family_name(self) -> str: ...
    @property
    def orthogonal(self) -> bool: ...
    @orthogonal.setter
    def orthogonal(self, value: bool) -> None: ...
    @property
    def biorthogonal(self) -> bool: ...
    @biorthogonal.setter
    def biorthogonal(self, value: bool) -> None: ...
    @property
    def complex_cwt(self) -> bool: ...
    @complex_cwt.setter
    def complex_cwt(self, value: bool) -> None: ...
    @property
    def lower_bound(self) -> Optional[float]: ...
    @lower_bound.setter
    def lower_bound(self, value: float) -> None: ...
    @property
    def upper_bound(self) -> Optional[float]: ...
    @upper_bound.setter
    def upper_bound(self, value: float) -> None: ...
    @property
    def center_frequency(self) -> Optional[float]: ...
    @center_frequency.setter
    def center_frequency(self, value: float) -> None: ...
    @property
    def bandwidth_frequency(self) -> Optional[float]: ...
    @bandwidth_frequency.setter
    def bandwidth_frequency(self, value: float) -> None: ...
    @property
    def fbsp_order(self) -> Optional[int]: ...
    @fbsp_order.setter
    def fbsp_order(self, value: int) -> None: ...
    @property
    def symmetry(self) -> _Symmetry: ...

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions