Skip to content

Commit e45af8e

Browse files
author
Jon Duckworth
authored
Merge pull request #562 from stac-utils/fix/rde/types
Fix some type issues exposed via the API
2 parents ac7b1d6 + d533785 commit e45af8e

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636

3737
- Added `Collections` as a type that can be extended for extensions whose fields can appear in collection summaries ([#547](https://github.com/stac-utils/pystac/pull/547))
3838
- Allow resolved self links when getting an object's self href ([#555](https://github.com/stac-utils/pystac/pull/555))
39+
- Fixed type annotation on SummariesLabelExtension.label_properties setter ([#562](https://github.com/stac-utils/pystac/pull/562))
40+
- Allow comparable types with alternate parameter naming of __lt__ method to pass structural type linting for RangeSummary ([#562](https://github.com/stac-utils/pystac/pull/562))
3941

4042
### Deprecated
4143

pystac/extensions/label.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ def label_properties(self) -> Optional[List[str]]:
722722
return self.summaries.get_list(PROPERTIES_PROP)
723723

724724
@label_properties.setter
725-
def label_properties(self, v: Optional[List[LabelClasses]]) -> None:
725+
def label_properties(self, v: Optional[List[str]]) -> None:
726726
self._set_summary(PROPERTIES_PROP, v)
727727

728728
@property

pystac/summaries.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,31 @@
3030
from abc import abstractmethod
3131

3232

33-
class Comparable(Protocol):
34-
"""Protocol for annotating comparable types."""
33+
class _Comparable_x(Protocol):
34+
"""Protocol for annotating comparable types.
35+
36+
For matching __lt__ that takes an 'x' parameter
37+
(e.g. float)
38+
"""
3539

3640
@abstractmethod
3741
def __lt__(self: "T", x: "T") -> bool:
3842
return NotImplemented
3943

4044

41-
T = TypeVar("T", bound=Comparable)
45+
class _Comparable_other(Protocol):
46+
"""Protocol for annotating comparable types.
47+
48+
For matching __lt___ that takes an 'other' parameter
49+
(e.g. datetime)
50+
"""
51+
52+
@abstractmethod
53+
def __lt__(self: "T", other: "T") -> bool:
54+
return NotImplemented
55+
56+
57+
T = TypeVar("T", bound=Union[_Comparable_x, _Comparable_other])
4258

4359

4460
class RangeSummary(Generic[T]):

0 commit comments

Comments
 (0)