Skip to content

Commit

Permalink
Back out some of the typing changes not compatible with Python 3.9
Browse files Browse the repository at this point in the history
  • Loading branch information
subagonsouth committed Sep 4, 2024
1 parent d7862b7 commit 97aa6a8
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions imap_processing/spice/kernels.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,33 @@
from collections.abc import Generator
from contextlib import contextmanager
from pathlib import Path
from typing import Callable, Optional, ParamSpec, TypeVar, overload
from typing import Any, Callable, Optional, overload

import numpy as np
import spiceypy as spice
from numpy.typing import NDArray
from spiceypy.utils.exceptions import SpiceyError

P = ParamSpec("P")
T = TypeVar("T")
logger = logging.getLogger(__name__)


# What is going on here? Taken from mypy help with declaring decorators
# Declarations to help with typing. Taken from mypy documentation on
# decorator-factories:
# https://mypy.readthedocs.io/en/stable/generics.html#decorator-factories
# Bare decorator usage
@overload
def ensure_spice(__func: Callable[P, T]) -> Callable[P, T]: ... # numpydoc ignore=GL08
def ensure_spice(
__func: Callable[..., Any],
) -> Callable[..., Any]: ... # numpydoc ignore=GL08
# Decorator with arguments
@overload
def ensure_spice(
*, time_kernels_only: bool = False
) -> Callable[[Callable[P, T]], Callable[P, T]]: ... # numpydoc ignore=GL08
) -> Callable[[Callable[..., Any]], Callable[..., Any]]: ... # numpydoc ignore=GL08
# Implementation
def ensure_spice(
__func: Optional[Callable[P, T]] = None, *, time_kernels_only: bool = False
) -> Callable[P, T] | Callable[[Callable[P, T]], Callable[P, T]]:
__func: Optional[Callable[..., Any]] = None, *, time_kernels_only: bool = False
) -> Callable[..., Any] | Callable[[Callable[..., Any]], Callable[..., Any]]:
"""
Decorator/wrapper that automatically furnishes SPICE kernels.
Expand Down Expand Up @@ -96,7 +97,7 @@ def ensure_spice(
... result = wrapped(*args, **kwargs)
"""

def _decorator(func: Callable[P, T]) -> Callable[P, T]:
def _decorator(func: Callable[..., Callable]) -> Callable:
"""
Decorate or wrap input function depending on how ensure_spice is used.
Expand All @@ -112,7 +113,7 @@ def _decorator(func: Callable[P, T]) -> Callable[P, T]:
"""

@functools.wraps(func)
def wrapper_ensure_spice(*args: P.args, **kwargs: P.kwargs) -> T:
def wrapper_ensure_spice(*args: Any, **kwargs: Any) -> Any:
"""
Wrap the function that ensure_spice is used on.
Expand Down

0 comments on commit 97aa6a8

Please sign in to comment.