Skip to content
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
23 changes: 10 additions & 13 deletions src/pystac/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from typing_extensions import deprecated

from .band import Band
from .common_metadata import DataValue, Instrument
from .media_type import MediaType
from .utils import is_absolute_href, make_absolute_href, make_relative_href
from .writer import Writer
Expand All @@ -14,7 +15,7 @@
from .stac_object import STACObject


class ItemAsset:
class ItemAsset(DataValue, Instrument):
def __init__(
self,
title: str | None = None,
Expand Down Expand Up @@ -51,18 +52,15 @@ def clone[T: ItemAsset](self: T) -> T:
return self.from_dict(self.to_dict())

def to_dict(self) -> dict[str, Any]:
data = copy.deepcopy(self.extra_fields)
if self.title is not None:
data["title"] = self.title
if self.description is not None:
data["description"] = self.description
if self.type is not None:
data["type"] = self.type
if self.roles is not None:
data["roles"] = self.roles
data: dict[str, Any] = copy.deepcopy(self.extra_fields)
data["title"] = self.title
data["description"] = self.description
data["type"] = self.type
data["roles"] = self.roles
data["statistics"] = self.statistics.to_dict() or None
if self.bands is not None:
data["bands"] = [band.to_dict() for band in self.bands]
return data
return {k: v for k, v in data.items() if v is not None}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the default behavior should be no null values in the output dict.



class Asset(ItemAsset):
Expand Down Expand Up @@ -117,8 +115,7 @@ def get_absolute_href(self) -> str | None:
@override
def to_dict(self) -> dict[str, Any]:
data = super().to_dict()
data["href"] = self.href
return data
return {"href": self.href, **data}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put the href first in the dict



class Assets(Protocol):
Expand Down
Loading