27
27
28
28
if TYPE_CHECKING :
29
29
from pystac .item import Asset as Asset_Type , Item as Item_Type
30
+ from pystac .collection import Collection as Collection_Type
30
31
31
32
32
33
class CatalogType (str , Enum ):
@@ -187,7 +188,7 @@ def is_relative(self) -> bool:
187
188
188
189
def add_child (
189
190
self ,
190
- child : "Catalog" ,
191
+ child : Union [ "Catalog" , "Collection_Type" ] ,
191
192
title : Optional [str ] = None ,
192
193
strategy : Optional [HrefLayoutStrategy ] = None ,
193
194
) -> None :
@@ -220,7 +221,9 @@ def add_child(
220
221
221
222
self .add_link (Link .child (child , title = title ))
222
223
223
- def add_children (self , children : Iterable ["Catalog" ]) -> None :
224
+ def add_children (
225
+ self , children : Iterable [Union ["Catalog" , "Collection_Type" ]]
226
+ ) -> None :
224
227
"""Adds links to multiple :class:`~pystac.Catalog` or `~pystac.Collection` objects.
225
228
This method will set each child's parent to this object, and their root to
226
229
this Catalog's root.
@@ -275,7 +278,9 @@ def add_items(self, items: Iterable["Item_Type"]) -> None:
275
278
for item in items :
276
279
self .add_item (item )
277
280
278
- def get_child (self , id : str , recursive : bool = False ) -> Optional ["Catalog" ]:
281
+ def get_child (
282
+ self , id : str , recursive : bool = False
283
+ ) -> Optional [Union ["Catalog" , "Collection_Type" ]]:
279
284
"""Gets the child of this catalog with the given ID, if it exists.
280
285
281
286
Args:
@@ -285,7 +290,8 @@ def get_child(self, id: str, recursive: bool = False) -> Optional["Catalog"]:
285
290
to False.
286
291
287
292
Return:
288
- Item or None: The item with the given ID, or None if not found.
293
+ Optional Catalog or Collection: The child with the given ID,
294
+ or None if not found.
289
295
"""
290
296
if not recursive :
291
297
return next ((c for c in self .get_children () if c .id == id ), None )
@@ -296,14 +302,17 @@ def get_child(self, id: str, recursive: bool = False) -> Optional["Catalog"]:
296
302
return child
297
303
return None
298
304
299
- def get_children (self ) -> Iterable ["Catalog" ]:
305
+ def get_children (self ) -> Iterable [Union [ "Catalog" , "Collection_Type" ] ]:
300
306
"""Return all children of this catalog.
301
307
302
308
Return:
303
- Iterable[Catalog]: Generator of children who's parent
309
+ Iterable[Catalog or Collection ]: Iterable of children who's parent
304
310
is this catalog.
305
311
"""
306
- return map (lambda x : cast (pystac .Catalog , x ), self .get_stac_objects ("child" ))
312
+ return map (
313
+ lambda x : cast (Union [pystac .Catalog , pystac .Collection ], x ),
314
+ self .get_stac_objects ("child" ),
315
+ )
307
316
308
317
def get_child_links (self ) -> List [Link ]:
309
318
"""Return all child links of this catalog.
0 commit comments