diff --git a/dascore/constants.py b/dascore/constants.py index 5a56b905..1f5c9e64 100644 --- a/dascore/constants.py +++ b/dascore/constants.py @@ -8,11 +8,11 @@ import numpy as np import pandas as pd -import dascore +import dascore as dc -PatchType = TypeVar("PatchType", bound="dascore.Patch") +PatchType = TypeVar("PatchType", bound="dc.Patch") -SpoolType = TypeVar("SpoolType", bound="dascore.BaseSpool") +SpoolType = TypeVar("SpoolType", bound="dc.BaseSpool") @runtime_checkable diff --git a/dascore/utils/patch.py b/dascore/utils/patch.py index 86350239..59b6173c 100644 --- a/dascore/utils/patch.py +++ b/dascore/utils/patch.py @@ -239,9 +239,9 @@ def patch_function( machinery multiple times from within another patch function. - If using `PatchType` or `SpoolType` type variables from the - [constants module](`dascore.constants`), you may need to import - dascore (not import dascore as dc) in the same file the patch function - is defined. + [constants module](`dascore.constants`), make sure dascore is imported + as dc at the top of the file where the patch function is defined so + the forward refs can be resolved properly for type checking. """ def _wrapper(func): diff --git a/scripts/_render_api.py b/scripts/_render_api.py index 9617606f..20299e19 100644 --- a/scripts/_render_api.py +++ b/scripts/_render_api.py @@ -93,6 +93,9 @@ def unpact_annotation(obj, data_dict, address_dict) -> str: # just assume the bound string is resolvable key = str(obj).split("('")[-1].replace("')", "") name = key.split(".")[-1] + # dc. is the same as dascore. + if key.startswith("dc."): + key = f"dascore.{key[3:]}" return f"[{name}](`{key}`)" # Array-like thing from numpy #TODO improve this elif "numpy.typing" in str_rep: diff --git a/tests/test_utils/test_patch_utils.py b/tests/test_utils/test_patch_utils.py index fd2e286f..2da8bbd2 100644 --- a/tests/test_utils/test_patch_utils.py +++ b/tests/test_utils/test_patch_utils.py @@ -10,7 +10,6 @@ import pytest from pydantic import Field -import dascore # noqa needed for PatchType import dascore as dc from dascore import patch_function from dascore.constants import PatchType