diff --git a/CHANGELOG.md b/CHANGELOG.md index cd6d1e5f5..5d1279eb8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ as `root.stac_io`, if that value is not `None` ([#590](https://github.com/stac-utils/pystac/pull/590)) - Links will get their `title` from their target if no `title` is provided ([#607](https://github.com/stac-utils/pystac/pull/607)) +- Relax typing on `LabelClasses` from `List` to `Sequence` ([#627](https://github.com/stac-utils/pystac/pull/627)) ### Fixed diff --git a/pystac/extensions/label.py b/pystac/extensions/label.py index 69313ec4d..ea2791cb3 100644 --- a/pystac/extensions/label.py +++ b/pystac/extensions/label.py @@ -5,7 +5,7 @@ from enum import Enum from pystac.extensions.base import ExtensionManagementMixin, SummariesExtension -from typing import Any, Dict, Iterable, List, Optional, Union, cast +from typing import Any, Dict, Iterable, List, Optional, Sequence, Union, cast import pystac from pystac.serialization.identify import STACJSONDescription, STACVersionID @@ -73,7 +73,7 @@ def __init__(self, properties: Dict[str, Any]): def apply( self, - classes: List[Union[str, int, float]], + classes: Sequence[Union[str, int, float]], name: Optional[str] = None, ) -> None: """Sets the properties for this instance. @@ -90,7 +90,7 @@ def apply( @classmethod def create( cls, - classes: List[Union[str, int, float]], + classes: Sequence[Union[str, int, float]], name: Optional[str] = None, ) -> "LabelClasses": """Creates a new :class:`~LabelClasses` instance. @@ -106,12 +106,12 @@ def create( return c @property - def classes(self) -> List[Union[str, int, float]]: + def classes(self) -> Sequence[Union[str, int, float]]: """Gets or sets the class values.""" return get_required(self.properties.get("classes"), self, "classes") @classes.setter - def classes(self, v: List[Union[str, int, float]]) -> None: + def classes(self, v: Sequence[Union[str, int, float]]) -> None: self.properties["classes"] = v @property diff --git a/tests/extensions/test_label.py b/tests/extensions/test_label.py index 93de2a468..4bcad266e 100644 --- a/tests/extensions/test_label.py +++ b/tests/extensions/test_label.py @@ -248,6 +248,10 @@ def test_label_classes(self) -> None: label_item.validate() + def test_label_classes_typing(self) -> None: + classes: List[str] = ["foo", "bar"] + LabelClasses.create(classes=classes) + def test_label_tasks(self) -> None: label_item = pystac.Item.from_file(self.label_example_1_uri)