Skip to content

Commit

Permalink
Tighten typing annotations (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
crusaderky committed Jan 12, 2024
1 parent 6fd9f4e commit d52bf72
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
14 changes: 8 additions & 6 deletions pyscenarios/duck.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def _apply_unary(func: Callable[[Any], Any]) -> Callable[[Any], Any]:
"""

@wraps(func)
def wrapper(x):
def wrapper(x: Any) -> Any:
if isinstance(x, da.Array):
sig = tuple(range(x.ndim))
return da.blockwise(func, sig, x, sig, dtype=float)
Expand All @@ -41,7 +41,7 @@ def _apply_binary(func: Callable[[Any, Any], Any]) -> Callable[[Any, Any], Any]:
"""

@wraps(func)
def wrapper(x, y):
def wrapper(x: Any, y: Any) -> Any:
x = array(x)
y = array(y)
if isinstance(x, da.Array) or isinstance(y, da.Array):
Expand All @@ -65,7 +65,7 @@ def _toplevel(func_name: str) -> Callable[..., np.ndarray | da.Array]:
np.func_name
"""

def wrapper(*args, **kwargs):
def wrapper(*args: Any, **kwargs: Any) -> np.ndarray | da.Array:
if any(isinstance(arg, da.Array) for arg in args):
func = getattr(da, func_name)
else:
Expand Down Expand Up @@ -102,18 +102,20 @@ def _apply(
func_name: str,
size: tuple[int, int] | None = None,
chunks: Chunks2D = None,
):
) -> Any:
if chunks is not None:
func = getattr(self._dask_state, func_name)
return func(size=size, chunks=chunks)
else:
func = getattr(self._numpy_state, func_name)
return func(size=size)

def uniform(self, size: tuple[int, int] | None = None, chunks: Chunks2D = None):
def uniform(
self, size: tuple[int, int] | None = None, chunks: Chunks2D = None
) -> np.ndarray | da.Array:
return self._apply("uniform", size=size, chunks=chunks)

def standard_normal(
self, size: tuple[int, int] | None = None, chunks: Chunks2D = None
):
) -> np.ndarray | da.Array:
return self._apply("standard_normal", size=size, chunks=chunks)
27 changes: 24 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ testpaths = pyscenarios/tests
markers =
slow: marks tests as slow (deselect with '-m "not slow"')

[coverage:report]
show_missing = true
exclude_lines =
pragma: nocover
pragma: no cover
TYPE_CHECKING
except ImportError
@overload
@(abc\.)?abstractmethod

[flake8]
# https://github.com/python/black#line-length
max-line-length = 88
Expand All @@ -78,6 +88,17 @@ force_grid_wrap = 0
use_parentheses = True
line_length = 88

# mypy: Ignore non-typed libraries
[mypy-*]
ignore_missing_imports = True
[mypy]
allow_incomplete_defs = false
# Doesn't work with numba @jit
allow_untyped_decorators = true
allow_untyped_defs = false
ignore_missing_imports = true
no_implicit_optional = true
show_error_codes = true
warn_redundant_casts = true
warn_unused_ignores = true
warn_unreachable = true

[mypy-*.tests.*]
allow_untyped_defs = true

0 comments on commit d52bf72

Please sign in to comment.