|
1 | 1 | from abc import ABC, abstractmethod |
2 | 2 | from enum import Enum |
3 | | -from typing import Any, Dict, Iterable, List, Optional, cast, TYPE_CHECKING, Union |
| 3 | +from typing import Any, Dict, Iterable, List, Optional, Type, cast, TYPE_CHECKING, Union |
4 | 4 |
|
5 | 5 | import pystac |
6 | 6 | from pystac import STACError |
@@ -272,25 +272,29 @@ def set_parent(self, parent: Optional["Catalog_Type"]) -> None: |
272 | 272 | self.add_link(Link.parent(parent)) |
273 | 273 |
|
274 | 274 | def get_stac_objects( |
275 | | - self, rel: Union[str, pystac.RelType] |
| 275 | + self, rel: Union[str, pystac.RelType], typ: Optional[Type["STACObject"]] = None |
276 | 276 | ) -> Iterable["STACObject"]: |
277 | 277 | """Gets the :class:`~pystac.STACObject` instances that are linked to |
278 | 278 | by links with their ``rel`` property matching the passed in argument. |
279 | 279 |
|
280 | 280 | Args: |
281 | 281 | rel : The relation to match each :class:`~pystac.Link`'s |
282 | 282 | ``rel`` property against. |
| 283 | + typ : If not ``None``, objects will only be yielded if they are instances of |
| 284 | + ``typ``. |
283 | 285 |
|
284 | 286 | Returns: |
285 | 287 | Iterable[STACObjects]: A possibly empty iterable of STACObjects that are |
286 | | - connected to this object through links with the given ``rel``. |
| 288 | + connected to this object through links with the given ``rel`` and are of |
| 289 | + type ``typ`` (if given). |
287 | 290 | """ |
288 | 291 | links = self.links[:] |
289 | 292 | for i in range(0, len(links)): |
290 | 293 | link = links[i] |
291 | 294 | if link.rel == rel: |
292 | 295 | link.resolve_stac_object(root=self.get_root()) |
293 | | - yield cast("STACObject", link.target) |
| 296 | + if typ is None or isinstance(link.target, typ): |
| 297 | + yield cast("STACObject", link.target) |
294 | 298 |
|
295 | 299 | def save_object( |
296 | 300 | self, |
|
0 commit comments