finally make mypy happy
MODIFY
pangeo_forge_recipes/executors/base.py
pangeo_forge_recipes/executors/base.py
+from __future__ import annotations
+
import enum
from dataclasses import dataclass
-from typing import Any, Dict, Generic, Hashable, Iterable, Optional, Protocol, TypeVar, Union
-
-# there is no good way to type hint a dataclass
-# https://stackoverflow.com/questions/54668000/type-hint-for-an-instance-of-a-non-specific-dataclass
-Config = Any
-
-
-# https://stackoverflow.com/questions/57837609/python-typing-signature-typing-callable-for-function-with-kwargs
-class NoArgumentStageFunction(Protocol):
- def __call__(*, config: Optional[Config] = None) -> None:
- ...
+from typing import Any, Callable, Dict, Generic, Iterable, Optional, TypeVar, Union
+from mypy_extensions import NamedArg
-class SingleArgumentStageFunction(Protocol):
- def __call__(__a: Hashable, *, config: Optional[Config] = None) -> None:
- ...
-
-
-# For some reason, mypy does not like this
+Config = Any # TODO: better typing for config
+SingleArgumentStageFunction = Callable[[Any, NamedArg(type=Any, name="config")], None] # noqa: F821
+NoArgumentStageFunction = Callable[[NamedArg(type=Any, name="config")], None] # noqa: F821
StageFunction = Union[NoArgumentStageFunction, SingleArgumentStageFunction]
-# pangeo_forge_recipes/recipes/xarray_zarr.py:525: error:
-# Argument "function" to "Stage" has incompatible type
-# "Callable[[Index, NamedArg(XarrayZarrRecipe, 'config')], None]";
-# expected "NoArgumentStageFunction" [arg-type]
-
-# TODO: fix this to be a stricter type as above
-# StageFunction = Callable
class StageAnnotationType(enum.Enum):

MODIFY
setup.cfg
setup.cfg
@@ -60,7 +60,7 @@ max-line-length = 100
[isort]
known_first_party=pangeo_forge_recipes
-known_third_party=aiohttp,click,dask,fsspec,fsspec_reference_maker,numpy,pandas,prefect,pytest,pytest_lazyfixture,setuptools,xarray,yaml,zarr
+known_third_party=aiohttp,click,dask,fsspec,fsspec_reference_maker,mypy_extensions,numpy,pandas,prefect,pytest,pytest_lazyfixture,setuptools,xarray,yaml,zarr
multi_line_output=3
include_trailing_comma=True
force_grid_wrap=0

finally make mypy happy