Skip to content

templates: add type hints to from_template / list_templates#3543

Merged
brendancol merged 1 commit into
mainfrom
deep-sweep-api-consistency-templates-2026-06-26
Jun 26, 2026
Merged

templates: add type hints to from_template / list_templates#3543
brendancol merged 1 commit into
mainfrom
deep-sweep-api-consistency-templates-2026-06-26

Conversation

@brendancol

Copy link
Copy Markdown
Contributor

Closes #3542.

Adds type annotations to the two public functions in xrspatial/templates.py:

def from_template(name: str,
                  resolution: Optional[Union[float, Tuple[float, float]]] = None,
                  *, preserve: Optional[str] = None, backend: str = "numpy",
                  fill: float = np.nan,
                  chunks: Union[int, str, Tuple] = "auto") -> xr.DataArray:

def list_templates(kind: Optional[str] = None) -> Union[Dict[str, List[str]], List[str]]:

Both functions previously had no hints, while the analogous DataArray constructor generate_terrain and most public entry points (slope, aspect, curvature, proximity, zonal, classify) are annotated. This brings the templates surface in line.

Non-breaking: signatures and runtime behavior are unchanged. Verified from_template across all four backends (numpy, dask+numpy, cupy, dask+cupy) on a CUDA host.

Adds test_public_functions_have_type_hints, which asserts both functions carry a return annotation and a hint on every parameter. Full test_templates.py passes (64 tested).

The resolution parameter intentionally maps to attrs['res']; that naming is left as is (res is the array-contract attr name, resolution is the clearer constructor parameter).

Found by the api-consistency sweep (category 3).

Annotate the two public template entry points to match the rest of the
public API (generate_terrain, slope, aspect, etc.). Non-breaking; adds a
test asserting both functions carry parameter and return annotations.

Also records the api-consistency sweep result for the templates module.
@brendancol brendancol merged commit 861c28c into main Jun 26, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

templates: add type hints to from_template / list_templates (api-consistency)

1 participant