Skip to content

slope() annotates name as str while aspect/curvature use Optional[str] #2681

@brendancol

Description

@brendancol

Summary

In xrspatial/slope.py, the public slope() function annotates its name parameter as name: str = 'slope'. The other terrain functions all annotate the same parameter as Optional[str]:

  • aspect() (aspect.py): name: Optional[str] = 'aspect'
  • northness() (aspect.py): name: Optional[str] = 'northness'
  • eastness() (aspect.py): name: Optional[str] = 'eastness'
  • curvature() (curvature.py): name: Optional[str] = 'curvature'

Why it matters

slope() hands name straight to xr.DataArray(name=name), which accepts None. So slope(agg, name=None) runs fine, but the str annotation tells type checkers and IDE users that None is invalid. The hint contradicts the runtime behavior and breaks consistency with the rest of the family.

Fix

Change the annotation to name: Optional[str] = 'slope' and import Optional in slope.py (the module currently imports only Union from typing). Widening a type hint accepts a superset of the old values, so this is non-breaking and needs no deprecation shim.

Severity

MEDIUM. A type-hint inconsistency that misleads users and tooling. Found by the api-consistency sweep.

Metadata

Metadata

Assignees

No one assigned

    Labels

    apiAPI design and consistencybugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions