Skip to content

Commit be5c264

Browse files
committed
Update docstrings for File Extension
1 parent e812001 commit be5c264

File tree

1 file changed

+48
-40
lines changed

1 file changed

+48
-40
lines changed

pystac/extensions/file.py

Lines changed: 48 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@
2424

2525
SCHEMA_URI = "https://stac-extensions.github.io/file/v1.0.0/schema.json"
2626

27-
DATA_TYPE_PROP = "file:data_type"
28-
SIZE_PROP = "file:size"
29-
NODATA_PROP = "file:nodata"
30-
CHECKSUM_PROP = "file:checksum"
27+
PREFIX = "file:"
28+
DATA_TYPE_PROP = PREFIX + "data_type"
29+
SIZE_PROP = PREFIX + "size"
30+
NODATA_PROP = PREFIX + "nodata"
31+
CHECKSUM_PROP = PREFIX + "checksum"
3132

3233

3334
class FileDataType(str, enum.Enum):
@@ -55,18 +56,19 @@ def __str__(self) -> str:
5556
class FileExtension(
5657
Generic[T], PropertiesExtension, ExtensionManagementMixin[pystac.Item]
5758
):
58-
"""FileItemExt is the extension of the Item in the file extension which
59-
adds file related details such as checksum, data type and size for assets.
59+
"""An abstract class that can be used to extend the properties of an
60+
:class:`~pystac.Item` or :class:`~pystac.Asset` with properties from the
61+
:stac-ext:`File Info Extension <file>`. This class is generic over the type of
62+
STAC Object to be extended (e.g. :class:`~pystac.Item`,
63+
:class:`~pystac.Asset`).
6064
61-
Args:
62-
item : The item to be extended.
65+
To create a concrete instance of :class:`FileExtension`, use the
66+
:meth:`FileExtension.ext` method. For example:
6367
64-
Attributes:
65-
item : The Item that is being extended.
68+
.. code-block:: python
6669
67-
Note:
68-
Using FileItemExt to directly wrap an item will add the 'file' extension ID to
69-
the item's stac_extensions.
70+
>>> item: pystac.Item = ...
71+
>>> file_ext = FileExtension.ext(item)
7072
"""
7173

7274
def apply(
@@ -92,11 +94,7 @@ def apply(
9294

9395
@property
9496
def data_type(self) -> Optional[FileDataType]:
95-
"""Get or sets the data_type of the file.
96-
97-
Returns:
98-
FileDataType
99-
"""
97+
"""Get or sets the data_type of the file."""
10098
return map_opt(
10199
lambda s: FileDataType(s), self._get_property(DATA_TYPE_PROP, str)
102100
)
@@ -107,11 +105,7 @@ def data_type(self, v: Optional[FileDataType]) -> None:
107105

108106
@property
109107
def size(self) -> Optional[int]:
110-
"""Get or sets the size in bytes of the file
111-
112-
Returns:
113-
int or None
114-
"""
108+
"""Get or sets the size in bytes of the file."""
115109
return self._get_property(SIZE_PROP, int)
116110

117111
@size.setter
@@ -120,7 +114,7 @@ def size(self, v: Optional[int]) -> None:
120114

121115
@property
122116
def nodata(self) -> Optional[List[Any]]:
123-
"""Get or sets the no data values"""
117+
"""Get or sets the no data values."""
124118
return self._get_property(NODATA_PROP, List[Any])
125119

126120
@nodata.setter
@@ -129,11 +123,7 @@ def nodata(self, v: Optional[List[Any]]) -> None:
129123

130124
@property
131125
def checksum(self) -> Optional[str]:
132-
"""Get or sets the checksum
133-
134-
Returns:
135-
str or None
136-
"""
126+
"""Get or sets the checksum"""
137127
return self._get_property(CHECKSUM_PROP, str)
138128

139129
@checksum.setter
@@ -146,6 +136,16 @@ def get_schema_uri(cls) -> str:
146136

147137
@staticmethod
148138
def ext(obj: T) -> "FileExtension[T]":
139+
"""Extends the given STAC Object with properties from the :stac-ext:`File Info
140+
Extension <file>`.
141+
142+
This extension can be applied to instances of :class:`~pystac.Item` or
143+
:class:`~pystac.Asset`.
144+
145+
Raises:
146+
147+
pystac.ExtensionTypeError : If an invalid object type is passed.
148+
"""
149149
if isinstance(obj, pystac.Item):
150150
return cast(FileExtension[T], ItemFileExtension(obj))
151151
elif isinstance(obj, pystac.Asset):
@@ -161,6 +161,14 @@ def summaries(obj: pystac.Collection) -> "SummariesFileExtension":
161161

162162

163163
class ItemFileExtension(FileExtension[pystac.Item]):
164+
"""A concrete implementation of :class:`FileExtension` on an :class:`~pystac.Item`
165+
that extends the properties of the Item to include properties defined in the
166+
:stac-ext:`File Info Extension <file>`.
167+
168+
This class should generally not be instantiated directly. Instead, call
169+
:meth:`FileExtension.ext` on an :class:`~pystac.Item` to extend it.
170+
"""
171+
164172
def __init__(self, item: pystac.Item):
165173
self.item = item
166174
self.properties = item.properties
@@ -170,6 +178,14 @@ def __repr__(self) -> str:
170178

171179

172180
class AssetFileExtension(FileExtension[pystac.Asset]):
181+
"""A concrete implementation of :class:`FileExtension` on an :class:`~pystac.Asset`
182+
that extends the Asset fields to include properties defined in the
183+
:stac-ext:`File Info Extension <info>`.
184+
185+
This class should generally not be instantiated directly. Instead, call
186+
:meth:`FileExtension.ext` on an :class:`~pystac.Asset` to extend it.
187+
"""
188+
173189
def __init__(self, asset: pystac.Asset):
174190
self.asset_href = asset.href
175191
self.properties = asset.properties
@@ -183,11 +199,7 @@ def __repr__(self) -> str:
183199
class SummariesFileExtension(SummariesExtension):
184200
@property
185201
def data_type(self) -> Optional[List[FileDataType]]:
186-
"""Get or sets the data_type of the file.
187-
188-
Returns:
189-
FileDataType
190-
"""
202+
"""Get or sets the summary of data_type values for this Collection."""
191203

192204
return map_opt(
193205
lambda x: [FileDataType(t) for t in x],
@@ -200,11 +212,7 @@ def data_type(self, v: Optional[List[FileDataType]]) -> None:
200212

201213
@property
202214
def size(self) -> Optional[pystac.RangeSummary[int]]:
203-
"""Get or sets the size in bytes of the file
204-
205-
Returns:
206-
int or None
207-
"""
215+
"""Get or sets the summary of size values for this Collection."""
208216
return self.summaries.get_range(SIZE_PROP)
209217

210218
@size.setter
@@ -213,7 +221,7 @@ def size(self, v: Optional[pystac.RangeSummary[int]]) -> None:
213221

214222
@property
215223
def nodata(self) -> Optional[List[Any]]:
216-
"""Get or sets the list of no data values"""
224+
"""Get or sets the summary of nodata values for this Collection."""
217225
return self.summaries.get_list(NODATA_PROP)
218226

219227
@nodata.setter

0 commit comments

Comments
 (0)