1111from pathlib import Path
1212from shutil import rmtree
1313from tempfile import mkdtemp
14- from typing import Any , Callable , Dict , Iterable , List , Optional , Union
14+ from typing import Any , Callable , Iterable , Optional , Union
1515
1616import fsspec
1717from boto3utils import s3
@@ -66,7 +66,7 @@ class Task(ABC):
6666
6767 def __init__ (
6868 self : "Task" ,
69- payload : Dict [str , Any ],
69+ payload : dict [str , Any ],
7070 workdir : Optional [PathLike ] = None ,
7171 save_workdir : Optional [bool ] = None ,
7272 skip_upload : bool = False , # deprecated
@@ -105,17 +105,17 @@ def __init__(
105105 )
106106
107107 @property
108- def process_definition (self ) -> Dict [str , Any ]:
108+ def process_definition (self ) -> dict [str , Any ]:
109109 process = self ._payload .get ("process" , {})
110110 if isinstance (process , dict ):
111111 return process
112112 else :
113113 raise ValueError (f"process is not a dict: { type (process )} " )
114114
115115 @property
116- def parameters (self ) -> Dict [str , Any ]:
116+ def parameters (self ) -> dict [str , Any ]:
117117 task_configs = self .process_definition .get ("tasks" , [])
118- if isinstance (task_configs , List ):
118+ if isinstance (task_configs , list ):
119119 warnings .warn (
120120 "task configs is list, use a dictionary instead" ,
121121 DeprecationWarning ,
@@ -125,13 +125,13 @@ def parameters(self) -> Dict[str, Any]:
125125 if len (task_config_list ) == 0 :
126126 return {}
127127 else :
128- task_config : Dict [str , Any ] = task_config_list [0 ]
128+ task_config : dict [str , Any ] = task_config_list [0 ]
129129 parameters = task_config .get ("parameters" , {})
130130 if isinstance (parameters , dict ):
131131 return parameters
132132 else :
133133 raise ValueError (f"parameters is not a dict: { type (parameters )} " )
134- elif isinstance (task_configs , Dict ):
134+ elif isinstance (task_configs , dict ):
135135 config = task_configs .get (self .name , {})
136136 if isinstance (config , dict ):
137137 return config
@@ -143,23 +143,23 @@ def parameters(self) -> Dict[str, Any]:
143143 raise ValueError (f"unexpected value for 'tasks': { task_configs } " )
144144
145145 @property
146- def upload_options (self ) -> Dict [str , Any ]:
146+ def upload_options (self ) -> dict [str , Any ]:
147147 upload_options = self .process_definition .get ("upload_options" , {})
148148 if isinstance (upload_options , dict ):
149149 return upload_options
150150 else :
151151 raise ValueError (f"upload_options is not a dict: { type (upload_options )} " )
152152
153153 @property
154- def collection_mapping (self ) -> Dict [str , str ]:
154+ def collection_mapping (self ) -> dict [str , str ]:
155155 collection_mapping = self .upload_options .get ("collections" , {})
156156 if isinstance (collection_mapping , dict ):
157157 return collection_mapping
158158 else :
159159 raise ValueError (f"collections is not a dict: { type (collection_mapping )} " )
160160
161161 @property
162- def items_as_dicts (self ) -> List [ Dict [str , Any ]]:
162+ def items_as_dicts (self ) -> list [ dict [str , Any ]]:
163163 features = self ._payload .get ("features" , [])
164164 if isinstance (features , list ):
165165 return features
@@ -172,14 +172,14 @@ def items(self) -> ItemCollection:
172172 return ItemCollection .from_dict (items_dict , preserve_dict = True )
173173
174174 @classmethod
175- def validate (cls , payload : Dict [str , Any ]) -> bool :
175+ def validate (cls , payload : dict [str , Any ]) -> bool :
176176 """Validates the payload and returns True if valid. If invalid, raises
177177 ``stactask.exceptions.FailedValidation`` or returns False."""
178178 # put validation logic on input Items and process definition here
179179 return True
180180
181181 @classmethod
182- def add_software_version (cls , items : List [ Dict [str , Any ]]) -> List [ Dict [str , Any ]]:
182+ def add_software_version (cls , items : list [ dict [str , Any ]]) -> list [ dict [str , Any ]]:
183183 warnings .warn (
184184 "add_software_version is deprecated, "
185185 "use add_software_version_to_item instead" ,
@@ -191,7 +191,7 @@ def add_software_version(cls, items: List[Dict[str, Any]]) -> List[Dict[str, Any
191191 return modified_items
192192
193193 @classmethod
194- def add_software_version_to_item (cls , item : Dict [str , Any ]) -> Dict [str , Any ]:
194+ def add_software_version_to_item (cls , item : dict [str , Any ]) -> dict [str , Any ]:
195195 """Adds software version information to a single item.
196196
197197 Uses the processing extension.
@@ -200,7 +200,7 @@ def add_software_version_to_item(cls, item: Dict[str, Any]) -> Dict[str, Any]:
200200 item: A single STAC item
201201
202202 Returns:
203- Dict [str, Any]: The same item with processing information applied.
203+ dict [str, Any]: The same item with processing information applied.
204204 """
205205 processing_ext = (
206206 "https://stac-extensions.github.io/processing/v1.1.0/schema.json"
@@ -249,7 +249,7 @@ def download_item_assets(
249249
250250 Args:
251251 item (pystac.Item): STAC Item for which assets need be downloaded.
252- assets (Optional[List [str]]): List of asset keys to download.
252+ assets (Optional[list [str]]): List of asset keys to download.
253253 Defaults to all assets.
254254 path_template (Optional[str]): String to be interpolated to specify
255255 where to store downloaded files.
@@ -274,15 +274,15 @@ def download_items_assets(
274274 path_template : str = "${collection}/${id}" ,
275275 keep_original_filenames : bool = False ,
276276 ** kwargs : Any ,
277- ) -> List [Item ]:
277+ ) -> list [Item ]:
278278 """Download provided asset keys for the given items. Assets are
279279 saved in workdir in a directory (as specified by path_template), and
280280 the items are updated with the new asset hrefs.
281281
282282 Args:
283- items (List [pystac.Item]): List of STAC Items for which assets need
283+ items (list [pystac.Item]): List of STAC Items for which assets need
284284 be downloaded.
285- assets (Optional[List [str]]): List of asset keys to download.
285+ assets (Optional[list [str]]): List of asset keys to download.
286286 Defaults to all assets.
287287 path_template (Optional[str]): String to be interpolated to specify
288288 where to store downloaded files.
@@ -304,7 +304,7 @@ def download_items_assets(
304304 def upload_item_assets_to_s3 (
305305 self ,
306306 item : Item ,
307- assets : Optional [List [str ]] = None ,
307+ assets : Optional [list [str ]] = None ,
308308 s3_client : Optional [s3 ] = None ,
309309 ) -> Item :
310310 if self ._upload :
@@ -319,7 +319,7 @@ def upload_item_assets_to_s3(
319319 def _is_local_asset (self , asset : Asset ) -> bool :
320320 return bool (asset .href .startswith (str (self ._workdir )))
321321
322- def _get_local_asset_keys (self , item : Item ) -> List [str ]:
322+ def _get_local_asset_keys (self , item : Item ) -> list [str ]:
323323 return [
324324 key for key , asset in item .assets .items () if self ._is_local_asset (asset )
325325 ]
@@ -337,7 +337,7 @@ def upload_local_item_assets_to_s3(
337337
338338 # this should be in PySTAC
339339 @staticmethod
340- def create_item_from_item (item : Dict [str , Any ]) -> Dict [str , Any ]:
340+ def create_item_from_item (item : dict [str , Any ]) -> dict [str , Any ]:
341341 new_item = deepcopy (item )
342342 # create a derived output item
343343 links = [
@@ -356,7 +356,7 @@ def create_item_from_item(item: Dict[str, Any]) -> Dict[str, Any]:
356356 return new_item
357357
358358 @abstractmethod
359- def process (self , ** kwargs : Any ) -> List [ Dict [str , Any ]]:
359+ def process (self , ** kwargs : Any ) -> list [ dict [str , Any ]]:
360360 """Main task logic - virtual
361361
362362 Returns:
@@ -366,7 +366,7 @@ def process(self, **kwargs: Any) -> List[Dict[str, Any]]:
366366 # do some stuff
367367 pass
368368
369- def post_process_item (self , item : Dict [str , Any ]) -> Dict [str , Any ]:
369+ def post_process_item (self , item : dict [str , Any ]) -> dict [str , Any ]:
370370 """Perform post-processing operations on an item.
371371
372372 E.g. add software version information.
@@ -380,15 +380,15 @@ def post_process_item(self, item: Dict[str, Any]) -> Dict[str, Any]:
380380 item: An item produced by :py:meth:`Task.process`
381381
382382 Returns:
383- Dict [str, Any]: The item with any additional attributes applied.
383+ dict [str, Any]: The item with any additional attributes applied.
384384 """
385385 assert "stac_extensions" in item
386386 assert isinstance (item ["stac_extensions" ], list )
387387 item ["stac_extensions" ].sort ()
388388 return item
389389
390390 @classmethod
391- def handler (cls , payload : Dict [str , Any ], ** kwargs : Any ) -> Dict [str , Any ]:
391+ def handler (cls , payload : dict [str , Any ], ** kwargs : Any ) -> dict [str , Any ]:
392392 task = None
393393 try :
394394 if "href" in payload or "url" in payload :
@@ -414,7 +414,7 @@ def handler(cls, payload: Dict[str, Any], **kwargs: Any) -> Dict[str, Any]:
414414 task .cleanup_workdir ()
415415
416416 @classmethod
417- def parse_args (cls , args : List [str ]) -> Dict [str , Any ]:
417+ def parse_args (cls , args : list [str ]) -> dict [str , Any ]:
418418 dhf = argparse .ArgumentDefaultsHelpFormatter
419419 parser0 = argparse .ArgumentParser (description = cls .description )
420420 parser0 .add_argument (
0 commit comments