Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Link.to_dict() should only contain strings #1114

Merged
merged 2 commits into from
May 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
- Use `pyproject.toml` instead of `setup.py` ([#1100](https://github.com/stac-utils/pystac/pull/1100))
- `DefaultStacIO` now raises an error if it tries to write to a non-local url ([#1107](https://github.com/stac-utils/pystac/pull/1107))
- Allow instantiation of pystac objects even with `"stac_extensions": null` ([#1109](https://github.com/stac-utils/pystac/pull/1109))
- Make `Link.to_dict()` only contain strings ([#1114](https://github.com/stac-utils/pystac/pull/1114))

### Deprecated

Expand Down
8 changes: 4 additions & 4 deletions pystac/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class Link(PathLike):
"""The relation of the link (e.g. 'child', 'item'). Registered rel Types are
preferred. See :class:`~pystac.RelType` for common media types."""

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

Expand All @@ -88,7 +88,7 @@ def __init__(
self,
rel: Union[str, pystac.RelType],
target: Union[str, STACObject],
media_type: Optional[str] = None,
media_type: Optional[Union[str, pystac.MediaType]] = None,
title: Optional[str] = None,
extra_fields: Optional[Dict[str, Any]] = None,
) -> None:
Expand Down Expand Up @@ -372,12 +372,12 @@ def to_dict(self, transform_href: bool = True) -> Dict[str, Any]:
"""

d: Dict[str, Any] = {
"rel": self.rel,
"rel": str(self.rel),
"href": self.get_href(transform_href=transform_href),
}

if self.media_type is not None:
d["type"] = self.media_type
d["type"] = str(self.media_type)

if self.title is not None:
d["title"] = self.title
Expand Down
4 changes: 2 additions & 2 deletions tests/test_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ def test_serialize_link(self) -> None:
link = pystac.Link(pystac.RelType.SELF, href, pystac.MediaType.JSON, title)
link_dict = link.to_dict()

self.assertEqual(str(link_dict["rel"]), "self")
self.assertEqual(str(link_dict["type"]), "application/json")
self.assertEqual(link_dict["rel"], "self")
self.assertEqual(link_dict["type"], "application/json")
self.assertEqual(link_dict["title"], title)
self.assertEqual(link_dict["href"], href)

Expand Down