Skip to content

Commit 83a6598

Browse files
author
Jon Duckworth
authored
Merge pull request #523 from l0b0/refactor/return-not-implemented-error-for-abstract-methods
refactor: Use `NotImplemented`/`NotImplementedError` as per docs
2 parents 664020e + a3bffe2 commit 83a6598

File tree

8 files changed

+18
-20
lines changed

8 files changed

+18
-20
lines changed

pystac/extensions/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class ExtensionManagementMixin(Generic[S], ABC):
9595
@abstractmethod
9696
def get_schema_uri(cls) -> str:
9797
"""Gets the schema URI associated with this extension."""
98-
pass
98+
raise NotImplementedError
9999

100100
@classmethod
101101
def add_to(cls, obj: S) -> None:

pystac/extensions/hooks.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class ExtensionHooks(ABC):
1414
@abstractmethod
1515
def schema_uri(self) -> str:
1616
"""The schema_uri for the current version of this extension"""
17-
pass
17+
raise NotImplementedError
1818

1919
@property
2020
@abstractmethod
@@ -24,13 +24,13 @@ def prev_extension_ids(self) -> Set[str]:
2424
property. Override with a class attribute so that the set of previous
2525
IDs is only created once.
2626
"""
27-
pass
27+
raise NotImplementedError
2828

2929
@property
3030
@abstractmethod
3131
def stac_object_types(self) -> Set[pystac.STACObjectType]:
3232
"""A set of STACObjectType for which migration logic will be applied."""
33-
pass
33+
raise NotImplementedError
3434

3535
@lru_cache()
3636
def _get_stac_object_types(self) -> Set[str]:

pystac/layout.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,17 +249,17 @@ def get_href(
249249
def get_catalog_href(
250250
self, cat: "Catalog_Type", parent_dir: str, is_root: bool
251251
) -> str:
252-
pass
252+
raise NotImplementedError
253253

254254
@abstractmethod
255255
def get_collection_href(
256256
self, col: "Collection_Type", parent_dir: str, is_root: bool
257257
) -> str:
258-
pass
258+
raise NotImplementedError
259259

260260
@abstractmethod
261261
def get_item_href(self, item: "Item_Type", parent_dir: str) -> str:
262-
pass
262+
raise NotImplementedError
263263

264264

265265
class CustomLayoutStrategy(HrefLayoutStrategy):

pystac/stac_io.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def read_text(
6262
Returns:
6363
str: The text contained in the file at the location specified by the uri.
6464
"""
65-
raise NotImplementedError("read_text not implemented")
65+
raise NotImplementedError
6666

6767
@abstractmethod
6868
def write_text(
@@ -79,7 +79,7 @@ def write_text(
7979
dest : The destination to write to.
8080
txt : The text to write.
8181
"""
82-
raise NotImplementedError("write_text not implemented")
82+
raise NotImplementedError
8383

8484
def json_loads(self, txt: str, *args: Any, **kwargs: Any) -> Dict[str, Any]:
8585
"""Method used internally by :class:`StacIO` instances to deserialize a

pystac/stac_object.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ def _object_links(self) -> List[str]:
424424
STACObjects linked to by this object (not including root, parent or self).
425425
This can include optional relations (which may not be present).
426426
"""
427-
pass
427+
raise NotImplementedError
428428

429429
@abstractmethod
430430
def to_dict(self, include_self_link: bool = True) -> Dict[str, Any]:
@@ -436,7 +436,7 @@ def to_dict(self, include_self_link: bool = True) -> Dict[str, Any]:
436436
437437
dict: A serialization of the object that can be written out as JSON.
438438
"""
439-
pass
439+
raise NotImplementedError
440440

441441
@abstractmethod
442442
def clone(self) -> "STACObject":
@@ -450,7 +450,7 @@ def clone(self) -> "STACObject":
450450
Returns:
451451
STACObject: The clone of this object.
452452
"""
453-
pass
453+
raise NotImplementedError
454454

455455
@classmethod
456456
def from_file(
@@ -521,7 +521,7 @@ def from_dict(
521521
Returns:
522522
STACObject: The STACObject parsed from this dict.
523523
"""
524-
pass
524+
raise NotImplementedError
525525

526526
@classmethod
527527
@abstractmethod
@@ -532,6 +532,4 @@ def matches_object_type(cls, d: Dict[str, Any]) -> bool:
532532
Args:
533533
d : A dictionary to identify
534534
"""
535-
raise NotImplementedError(
536-
"identify_dict must be implemented by the STACObject subclass."
537-
)
535+
raise NotImplementedError

pystac/summaries.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class Comparable(Protocol):
3535

3636
@abstractmethod
3737
def __lt__(self: "T", x: "T") -> bool:
38-
pass
38+
return NotImplemented
3939

4040

4141
T = TypeVar("T", bound=Comparable)

pystac/validation/schema_uri_map.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def get_object_schema_uri(
2828
Returns:
2929
str: The URI of the schema, or None if not found.
3030
"""
31-
pass
31+
raise NotImplementedError
3232

3333

3434
class DefaultSchemaUriMap(SchemaUriMap):

pystac/validation/stac_validator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def validate_core(
4444
stac_version : The version of STAC to validate the object against.
4545
href : Optional HREF of the STAC object being validated.
4646
"""
47-
pass
47+
raise NotImplementedError
4848

4949
@abstractmethod
5050
def validate_extension(
@@ -67,7 +67,7 @@ def validate_extension(
6767
extension_id : The extension ID of the extension to validate against.
6868
href : Optional HREF of the STAC object being validated.
6969
"""
70-
pass
70+
raise NotImplementedError
7171

7272
def validate(
7373
self,

0 commit comments

Comments
 (0)