Skip to content

Commit

Permalink
allow dc typevar forward refs
Browse files Browse the repository at this point in the history
  • Loading branch information
d-chambers committed Nov 8, 2024
1 parent c26966c commit 2ad9db9
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
6 changes: 3 additions & 3 deletions dascore/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions dascore/utils/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
3 changes: 3 additions & 0 deletions scripts/_render_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 0 additions & 1 deletion tests/test_utils/test_patch_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2ad9db9

Please sign in to comment.