Skip to content

Commit 1a02b9f

Browse files
committed
refactor: Avoid implicit re-exports in main module
1 parent f2afd5a commit 1a02b9f

File tree

2 files changed

+27
-28
lines changed

2 files changed

+27
-28
lines changed

pystac/collection.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@
1818
import dateutil.parser
1919
from dateutil import tz
2020

21-
import pystac
22-
from pystac import STACObjectType, CatalogType
21+
from pystac.rel_type import RelType
22+
from pystac.stac_io import StacIO
23+
from pystac.stac_object import STACObjectType
2324
from pystac.asset import Asset
24-
from pystac.catalog import Catalog
25+
from pystac.catalog import Catalog, CatalogType
2526
from pystac.layout import HrefLayoutStrategy
2627
from pystac.link import Link
2728
from pystac.utils import datetime_to_str
@@ -653,7 +654,7 @@ def clone(self) -> "Collection":
653654
clone._resolved_objects.cache(clone)
654655

655656
for link in self.links:
656-
if link.rel == pystac.RelType.ROOT:
657+
if link.rel == RelType.ROOT:
657658
# Collection __init__ sets correct root to clone; don't reset
658659
# if the root link points to self
659660
root_is_self = link.is_resolved() and link.target is self
@@ -721,11 +722,11 @@ def from_dict(
721722
)
722723

723724
for link in links:
724-
if link["rel"] == pystac.RelType.ROOT:
725+
if link["rel"] == RelType.ROOT:
725726
# Remove the link that's generated in Catalog's constructor.
726-
collection.remove_links(pystac.RelType.ROOT)
727+
collection.remove_links(RelType.ROOT)
727728

728-
if link["rel"] != pystac.RelType.SELF or href is None:
729+
if link["rel"] != RelType.SELF or href is None:
729730
collection.add_link(Link.from_dict(link))
730731

731732
if assets is not None:
@@ -764,12 +765,10 @@ def full_copy(
764765
return cast(Collection, super().full_copy(root, parent))
765766

766767
@classmethod
767-
def from_file(
768-
cls, href: str, stac_io: Optional[pystac.StacIO] = None
769-
) -> "Collection":
768+
def from_file(cls, href: str, stac_io: Optional[StacIO] = None) -> "Collection":
770769
result = super().from_file(href, stac_io)
771770
if not isinstance(result, Collection):
772-
raise pystac.STACTypeError(f"{result} is not a {Collection}.")
771+
raise STACTypeError(f"{result} is not a {Collection}.")
773772
return result
774773

775774
@classmethod

pystac/item_collection.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@
22
from pystac.errors import STACTypeError
33
from typing import Any, Dict, Iterator, List, Optional, Collection, Iterable, Union
44

5-
import pystac
5+
from pystac.item import Item
6+
from pystac.stac_io import StacIO
7+
from pystac.stac_object import STACObjectType
68
from pystac.utils import make_absolute_href, is_absolute_href
79
from pystac.serialization.identify import identify_stac_object_type
810

911

10-
ItemLike = Union[pystac.Item, Dict[str, Any]]
12+
ItemLike = Union[Item, Dict[str, Any]]
1113

1214

13-
class ItemCollection(Collection[pystac.Item]):
15+
class ItemCollection(Collection[Item]):
1416
"""Implementation of a GeoJSON FeatureCollection whose features are all STAC
1517
Items.
1618
@@ -70,7 +72,7 @@ class ItemCollection(Collection[pystac.Item]):
7072
# If an item is present in both ItemCollections it will only be added once
7173
"""
7274

73-
items: List[pystac.Item]
75+
items: List[Item]
7476
"""List of :class:`pystac.Item` instances contained in this ``ItemCollection``."""
7577

7678
extra_fields: Dict[str, Any]
@@ -83,20 +85,20 @@ def __init__(
8385
extra_fields: Optional[Dict[str, Any]] = None,
8486
clone_items: bool = False,
8587
):
86-
def map_item(item_or_dict: ItemLike) -> pystac.Item:
88+
def map_item(item_or_dict: ItemLike) -> Item:
8789
# Converts dicts to pystac.Items and clones if necessary
88-
if isinstance(item_or_dict, pystac.Item):
90+
if isinstance(item_or_dict, Item):
8991
return item_or_dict.clone() if clone_items else item_or_dict
9092
else:
91-
return pystac.Item.from_dict(item_or_dict)
93+
return Item.from_dict(item_or_dict)
9294

9395
self.items = list(map(map_item, items))
9496
self.extra_fields = extra_fields or {}
9597

96-
def __getitem__(self, idx: int) -> pystac.Item:
98+
def __getitem__(self, idx: int) -> Item:
9799
return self.items[idx]
98100

99-
def __iter__(self) -> Iterator[pystac.Item]:
101+
def __iter__(self) -> Iterator[Item]:
100102
return iter(self.items)
101103

102104
def __len__(self) -> int:
@@ -151,25 +153,23 @@ def from_dict(
151153
raise STACTypeError("Dict is not a valid ItemCollection")
152154

153155
items = [
154-
pystac.Item.from_dict(item, preserve_dict=preserve_dict)
156+
Item.from_dict(item, preserve_dict=preserve_dict)
155157
for item in d.get("features", [])
156158
]
157159
extra_fields = {k: v for k, v in d.items() if k not in ("features", "type")}
158160

159161
return cls(items=items, extra_fields=extra_fields)
160162

161163
@classmethod
162-
def from_file(
163-
cls, href: str, stac_io: Optional[pystac.StacIO] = None
164-
) -> "ItemCollection":
164+
def from_file(cls, href: str, stac_io: Optional[StacIO] = None) -> "ItemCollection":
165165
"""Reads a :class:`ItemCollection` from a JSON file.
166166
167167
Arguments:
168168
href : Path to the file.
169169
stac_io : A :class:`~pystac.StacIO` instance to use for file I/O
170170
"""
171171
if stac_io is None:
172-
stac_io = pystac.StacIO.default()
172+
stac_io = StacIO.default()
173173

174174
if not is_absolute_href(href):
175175
href = make_absolute_href(href)
@@ -181,7 +181,7 @@ def from_file(
181181
def save_object(
182182
self,
183183
dest_href: str,
184-
stac_io: Optional[pystac.StacIO] = None,
184+
stac_io: Optional[StacIO] = None,
185185
) -> None:
186186
"""Saves this instance to the ``dest_href`` location.
187187
@@ -191,7 +191,7 @@ def save_object(
191191
will use the default instance.
192192
"""
193193
if stac_io is None:
194-
stac_io = pystac.StacIO.default()
194+
stac_io = StacIO.default()
195195

196196
stac_io.save_json(dest_href, self.to_dict())
197197

@@ -217,6 +217,6 @@ def is_item_collection(d: Dict[str, Any]) -> bool:
217217
# Prior to STAC 0.9 ItemCollections did not have a stac_version field and could
218218
# only be identified by the fact that all of their 'features' are STAC Items.
219219
return all(
220-
identify_stac_object_type(feature) == pystac.STACObjectType.ITEM
220+
identify_stac_object_type(feature) == STACObjectType.ITEM
221221
for feature in d.get("features", [])
222222
)

0 commit comments

Comments
 (0)