Skip to content

Commit bb97a99

Browse files
jsignellgadomski
authored andcommitted
Link.to_dict() should only contain strings
1 parent 70efbb6 commit bb97a99

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

pystac/link.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class Link(PathLike):
6767
"""The relation of the link (e.g. 'child', 'item'). Registered rel Types are
6868
preferred. See :class:`~pystac.RelType` for common media types."""
6969

70-
media_type: Optional[str]
70+
media_type: Optional[Union[str, pystac.MediaType]]
7171
"""Optional description of the media type. Registered Media Types are preferred.
7272
See :class:`~pystac.MediaType` for common media types."""
7373

@@ -88,7 +88,7 @@ def __init__(
8888
self,
8989
rel: Union[str, pystac.RelType],
9090
target: Union[str, STACObject],
91-
media_type: Optional[str] = None,
91+
media_type: Optional[Union[str, pystac.MediaType]] = None,
9292
title: Optional[str] = None,
9393
extra_fields: Optional[Dict[str, Any]] = None,
9494
) -> None:
@@ -372,12 +372,12 @@ def to_dict(self, transform_href: bool = True) -> Dict[str, Any]:
372372
"""
373373

374374
d: Dict[str, Any] = {
375-
"rel": self.rel,
375+
"rel": str(self.rel),
376376
"href": self.get_href(transform_href=transform_href),
377377
}
378378

379379
if self.media_type is not None:
380-
d["type"] = self.media_type
380+
d["type"] = str(self.media_type)
381381

382382
if self.title is not None:
383383
d["title"] = self.title

tests/test_link.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,8 @@ def test_serialize_link(self) -> None:
205205
link = pystac.Link(pystac.RelType.SELF, href, pystac.MediaType.JSON, title)
206206
link_dict = link.to_dict()
207207

208-
self.assertEqual(str(link_dict["rel"]), "self")
209-
self.assertEqual(str(link_dict["type"]), "application/json")
208+
self.assertEqual(link_dict["rel"], "self")
209+
self.assertEqual(link_dict["type"], "application/json")
210210
self.assertEqual(link_dict["title"], title)
211211
self.assertEqual(link_dict["href"], href)
212212

0 commit comments

Comments
 (0)