Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Sequence for annotations for label classes #627

Merged
merged 2 commits into from
Sep 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 5 additions & 5 deletions pystac/extensions/label.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions tests/extensions/test_label.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down