Skip to content

Commit 1a99be6

Browse files
schwehrGoogle Earth Engine Authors
authored andcommitted
Switch Dict, List, and other typing imports to dict, list, etc.
PiperOrigin-RevId: 687420028
1 parent d6408ad commit 1a99be6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+362
-363
lines changed

python/ee/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import inspect
1111
import os
1212
import re
13-
from typing import Any, Hashable, List as ListType, Optional, Sequence, Tuple, Type, Union
13+
from typing import Any, Hashable, Optional, Sequence, Union
1414

1515
from ee import _utils
1616
from ee import batch
@@ -64,7 +64,7 @@
6464
_HAS_DYNAMIC_ATTRIBUTES = True
6565

6666
# A list of autogenerated class names added by _InitializeGeneratedClasses.
67-
_generatedClasses: ListType[str] = []
67+
_generatedClasses: list[str] = []
6868

6969
NO_PROJECT_EXCEPTION = ('ee.Initialize: no project found. Call with project='
7070
' or see http://goo.gle/ee-auth.')
@@ -434,7 +434,7 @@ def _InitializeGeneratedClasses() -> None:
434434
types._registerClasses(globals()) # pylint: disable=protected-access
435435

436436

437-
def _MakeClass(name: str) -> Type[Any]:
437+
def _MakeClass(name: str) -> type[Any]:
438438
"""Generates a dynamic API class for a given name."""
439439

440440
def init(self, *args, **kwargs):

python/ee/_arg_types.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from __future__ import annotations
33

44
import datetime
5-
from typing import Any as AnyType, Dict, List as ListType, Sequence, Tuple, Union
5+
from typing import Any as AnyType, Sequence, Union
66

77
from ee import classifier
88
from ee import clusterer
@@ -27,7 +27,7 @@
2727

2828
Array = Union[
2929
AnyType,
30-
ListType[AnyType],
30+
list[AnyType],
3131
ee_array.Array,
3232
ee_list.List,
3333
computedobject.ComputedObject,
@@ -43,7 +43,7 @@
4343
]
4444
DateRange = Union[daterange.DateRange, computedobject.ComputedObject]
4545
Dictionary = Union[
46-
Dict[AnyType, AnyType],
46+
dict[AnyType, AnyType],
4747
Sequence[AnyType],
4848
dictionary.Dictionary,
4949
computedobject.ComputedObject,
@@ -68,9 +68,9 @@
6868
Integer = Union[int, ee_number.Number, computedobject.ComputedObject]
6969
Kernel = Union[kernel.Kernel, computedobject.ComputedObject]
7070
List = Union[
71-
ListType[AnyType],
72-
Tuple[()],
73-
Tuple[AnyType, AnyType],
71+
list[AnyType],
72+
tuple[()],
73+
tuple[AnyType, AnyType],
7474
ee_list.List,
7575
computedobject.ComputedObject,
7676
]

python/ee/_cloud_api_utils.py

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import json
1212
import os
1313
import re
14-
from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Type, Union
14+
from typing import Any, Callable, Optional, Sequence, Union
1515
import warnings
1616

1717
import google_auth_httplib2
@@ -54,10 +54,10 @@ def request( # pylint: disable=invalid-name
5454
uri: str,
5555
method: str = 'GET',
5656
body: Optional[str] = None,
57-
headers: Optional[Dict[str, str]] = None,
57+
headers: Optional[dict[str, str]] = None,
5858
redirections: Optional[int] = None,
59-
connection_type: Optional[Type[Any]] = None,
60-
) -> Tuple[httplib2.Response, Any]:
59+
connection_type: Optional[type[Any]] = None,
60+
) -> tuple[httplib2.Response, Any]:
6161
"""Makes an HTTP request using httplib2 semantics."""
6262
del connection_type # Ignored
6363
del redirections # Ignored
@@ -84,7 +84,7 @@ def request( # pylint: disable=invalid-name
8484

8585

8686
def _wrap_request(
87-
headers_supplier: Callable[[], Dict[str, Any]],
87+
headers_supplier: Callable[[], dict[str, Any]],
8888
response_inspector: Callable[[Any], None],
8989
) -> Callable[..., http.HttpRequest]:
9090
"""Builds a callable that wraps an API request.
@@ -146,7 +146,7 @@ def build_cloud_resource(
146146
api_key: Optional[str] = None,
147147
credentials: Optional[Any] = None,
148148
timeout: Optional[float] = None,
149-
headers_supplier: Optional[Callable[[], Dict[str, Any]]] = None,
149+
headers_supplier: Optional[Callable[[], dict[str, Any]]] = None,
150150
response_inspector: Optional[Callable[[Any], None]] = None,
151151
http_transport: Optional[Any] = None,
152152
raw: Optional[bool] = False,
@@ -252,12 +252,12 @@ def build_cloud_resource_from_document(
252252

253253

254254
def _convert_dict(
255-
to_convert: Dict[str, Any],
256-
conversions: Dict[str, Any],
257-
defaults: Optional[Dict[str, Any]] = None,
255+
to_convert: dict[str, Any],
256+
conversions: dict[str, Any],
257+
defaults: Optional[dict[str, Any]] = None,
258258
key_warnings: bool = False,
259259
retain_keys: bool = False,
260-
) -> Dict[str, Any]:
260+
) -> dict[str, Any]:
261261
"""Applies a set of conversion rules to a dict.
262262
263263
Args:
@@ -290,7 +290,7 @@ def _convert_dict(
290290
The "to_convert" dict with keys renamed, values converted, and defaults
291291
added.
292292
"""
293-
result: Dict[str, Any] = {}
293+
result: dict[str, Any] = {}
294294
for key, value in to_convert.items():
295295
if key in conversions:
296296
conversion = conversions[key]
@@ -315,7 +315,7 @@ def _convert_dict(
315315

316316

317317
def _convert_value(
318-
value: str, conversions: Dict[str, Any], default: Any) -> Any:
318+
value: str, conversions: dict[str, Any], default: Any) -> Any:
319319
"""Converts a value using a set of value mappings.
320320
321321
Args:
@@ -374,7 +374,7 @@ def _convert_bounding_box_to_geo_json(bbox: Sequence[float]) -> str:
374374
lng_min, lat_min, lng_max, lat_max))
375375

376376

377-
def convert_get_list_params_to_list_assets_params(params) -> Dict[str, Any]:
377+
def convert_get_list_params_to_list_assets_params(params) -> dict[str, Any]:
378378
"""Converts a getList params dict to something usable with listAssets."""
379379
params = _convert_dict(
380380
params, {
@@ -393,7 +393,7 @@ def convert_get_list_params_to_list_assets_params(params) -> Dict[str, Any]:
393393
return convert_list_images_params_to_list_assets_params(params)
394394

395395

396-
def convert_list_assets_result_to_get_list_result(result) -> List[Any]:
396+
def convert_list_assets_result_to_get_list_result(result) -> list[Any]:
397397
"""Converts a listAssets result to something getList can return."""
398398
if 'assets' not in result:
399399
return []
@@ -444,8 +444,8 @@ def _convert_list_images_filter_params_to_list_assets_params(params) -> str:
444444

445445

446446
def convert_list_images_params_to_list_assets_params(
447-
params: Dict[str, Any]
448-
) -> Dict[str, Any]:
447+
params: dict[str, Any]
448+
) -> dict[str, Any]:
449449
"""Converts a listImages params dict to something usable with listAssets."""
450450
params = params.copy()
451451
extra_filters = _convert_list_images_filter_params_to_list_assets_params(
@@ -462,14 +462,14 @@ def is_asset_root(asset_name: str) -> bool:
462462
return bool(re.match(ASSET_ROOT_PATTERN, asset_name))
463463

464464

465-
def convert_list_images_result_to_get_list_result(result) -> List[Any]:
465+
def convert_list_images_result_to_get_list_result(result) -> list[Any]:
466466
"""Converts a listImages result to something getList can return."""
467467
if 'images' not in result:
468468
return []
469469
return [_convert_image_for_get_list_result(i) for i in result['images']]
470470

471471

472-
def _convert_asset_for_get_list_result(asset) -> Dict[str, Any]:
472+
def _convert_asset_for_get_list_result(asset) -> dict[str, Any]:
473473
"""Converts an EarthEngineAsset to the format returned by getList."""
474474
result = _convert_dict(
475475
asset, {
@@ -480,7 +480,7 @@ def _convert_asset_for_get_list_result(asset) -> Dict[str, Any]:
480480
return result
481481

482482

483-
def _convert_image_for_get_list_result(asset) -> Dict[str, Any]:
483+
def _convert_image_for_get_list_result(asset) -> dict[str, Any]:
484484
"""Converts an Image to the format returned by getList."""
485485
result = _convert_dict(
486486
asset, {
@@ -531,7 +531,7 @@ def convert_asset_id_to_asset_name(asset_id: str) -> str:
531531
return 'projects/earthengine-public/assets/{}'.format(asset_id)
532532

533533

534-
def split_asset_name(asset_name: str) -> Tuple[str, str]:
534+
def split_asset_name(asset_name: str) -> tuple[str, str]:
535535
"""Splits an asset name into the parent and ID parts.
536536
537537
Args:
@@ -556,7 +556,7 @@ def convert_task_id_to_operation_name(task_id: str) -> str:
556556
return 'projects/{}/operations/{}'.format(_cloud_api_user_project, task_id)
557557

558558

559-
def convert_params_to_image_manifest(params: Dict[str, Any]) -> Dict[str, Any]:
559+
def convert_params_to_image_manifest(params: dict[str, Any]) -> dict[str, Any]:
560560
"""Converts params to an ImageManifest for ingestion."""
561561
return _convert_dict(
562562
params, {
@@ -566,7 +566,7 @@ def convert_params_to_image_manifest(params: Dict[str, Any]) -> Dict[str, Any]:
566566
retain_keys=True)
567567

568568

569-
def convert_params_to_table_manifest(params: Dict[str, Any]) -> Dict[str, Any]:
569+
def convert_params_to_table_manifest(params: dict[str, Any]) -> dict[str, Any]:
570570
"""Converts params to a TableManifest for ingestion."""
571571
return _convert_dict(
572572
params, {
@@ -576,7 +576,7 @@ def convert_params_to_table_manifest(params: Dict[str, Any]) -> Dict[str, Any]:
576576
retain_keys=True)
577577

578578

579-
def convert_tilesets_to_one_platform_tilesets(tilesets: List[Any]) -> List[Any]:
579+
def convert_tilesets_to_one_platform_tilesets(tilesets: list[Any]) -> list[Any]:
580580
"""Converts a tileset to a one platform representation of a tileset."""
581581
converted_tilesets = []
582582
for tileset in tilesets:
@@ -588,7 +588,7 @@ def convert_tilesets_to_one_platform_tilesets(tilesets: List[Any]) -> List[Any]:
588588
return converted_tilesets
589589

590590

591-
def convert_sources_to_one_platform_sources(sources: List[Any]) -> List[Any]:
591+
def convert_sources_to_one_platform_sources(sources: list[Any]) -> list[Any]:
592592
"""Converts the sources to one platform representation of sources."""
593593
converted_sources = []
594594
for source in sources:
@@ -607,7 +607,7 @@ def convert_sources_to_one_platform_sources(sources: List[Any]) -> List[Any]:
607607
return converted_sources
608608

609609

610-
def encode_number_as_cloud_value(number: float) -> Dict[str, Union[float, str]]:
610+
def encode_number_as_cloud_value(number: float) -> dict[str, Union[float, str]]:
611611
# Numeric values in constantValue-style nodes end up stored in doubles. If the
612612
# input is an integer that loses precision as a double, use the int64 slot
613613
# ("integerValue") in ValueNode.
@@ -617,7 +617,7 @@ def encode_number_as_cloud_value(number: float) -> Dict[str, Union[float, str]]:
617617
return {'constantValue': number}
618618

619619

620-
def convert_algorithms(algorithms) -> Dict[str, Any]:
620+
def convert_algorithms(algorithms) -> dict[str, Any]:
621621
"""Converts a ListAlgorithmsResult to the internal format.
622622
623623
The internal code expects a dict mapping each algorithm's name to a dict
@@ -645,7 +645,7 @@ def convert_algorithms(algorithms) -> Dict[str, Any]:
645645
return dict(_convert_algorithm(algorithm) for algorithm in algs)
646646

647647

648-
def _convert_algorithm(algorithm: Dict[str, Any]) -> Tuple[str, Dict[str, Any]]:
648+
def _convert_algorithm(algorithm: dict[str, Any]) -> tuple[str, dict[str, Any]]:
649649
"""Converts an Algorithm to the internal format."""
650650
# Strip leading 'algorithms/' from the name.
651651
algorithm_name = algorithm['name'][11:]
@@ -669,11 +669,11 @@ def _convert_algorithm(algorithm: Dict[str, Any]) -> Tuple[str, Dict[str, Any]]:
669669

670670

671671
def _convert_algorithm_arguments(
672-
args: List[Dict[str, Any]]) -> List[Dict[str, Any]]:
672+
args: list[dict[str, Any]]) -> list[dict[str, Any]]:
673673
return [_convert_algorithm_argument(arg) for arg in args]
674674

675675

676-
def _convert_algorithm_argument(arg: Dict[str, Any]) -> Dict[str, Any]:
676+
def _convert_algorithm_argument(arg: dict[str, Any]) -> dict[str, Any]:
677677
return _convert_dict(
678678
arg, {
679679
'argumentName': 'name',
@@ -738,7 +738,7 @@ def convert_to_table_file_format(format_str: Optional[str]) -> str:
738738
return format_str
739739

740740

741-
def convert_to_band_list(bands: Union[List[str], None, str]) -> List[str]:
741+
def convert_to_band_list(bands: Union[list[str], None, str]) -> list[str]:
742742
"""Converts a band list, possibly as CSV, to a real list of bands.
743743
744744
Args:
@@ -758,7 +758,7 @@ def convert_to_band_list(bands: Union[List[str], None, str]) -> List[str]:
758758
raise ee_exception.EEException('Invalid band list ' + bands)
759759

760760

761-
def convert_to_visualization_options(params: Dict[str, Any]) -> Dict[str, Any]:
761+
def convert_to_visualization_options(params: dict[str, Any]) -> dict[str, Any]:
762762
"""Extracts a VisualizationOptions from a param dict.
763763
764764
Args:
@@ -821,14 +821,14 @@ def convert_to_visualization_options(params: Dict[str, Any]) -> Dict[str, Any]:
821821
return result
822822

823823

824-
def _convert_csv_numbers_to_list(value: str) -> List[float]:
824+
def _convert_csv_numbers_to_list(value: str) -> list[float]:
825825
"""Converts a string containing CSV numbers to a list."""
826826
if not value:
827827
return []
828828
return [float(x) for x in value.split(',')]
829829

830830

831-
def convert_operation_to_task(operation: Dict[str, Any]) -> Dict[str, Any]:
831+
def convert_operation_to_task(operation: dict[str, Any]) -> dict[str, Any]:
832832
"""Converts an Operation to a legacy Task."""
833833
result = _convert_dict(
834834
operation['metadata'], {
@@ -864,7 +864,7 @@ def _convert_operation_state_to_task_state(state: str) -> str:
864864
}, 'UNKNOWN')
865865

866866

867-
def convert_iam_policy_to_acl(policy: Dict[str, Any]) -> Dict[str, Any]:
867+
def convert_iam_policy_to_acl(policy: dict[str, Any]) -> dict[str, Any]:
868868
"""Converts an IAM Policy proto to the legacy ACL format."""
869869
bindings = {
870870
binding['role']: binding.get('members', [])
@@ -884,7 +884,7 @@ def convert_iam_policy_to_acl(policy: Dict[str, Any]) -> Dict[str, Any]:
884884
return result
885885

886886

887-
def convert_acl_to_iam_policy(acl: Dict[str, Any]) -> Dict[str, Any]:
887+
def convert_acl_to_iam_policy(acl: dict[str, Any]) -> dict[str, Any]:
888888
"""Converts the legacy ACL format to an IAM Policy proto."""
889889
owners = acl.get('owners', [])
890890
readers = acl.get('readers', [])
@@ -903,7 +903,7 @@ def convert_acl_to_iam_policy(acl: Dict[str, Any]) -> Dict[str, Any]:
903903

904904
def convert_to_grid_dimensions(
905905
dimensions: Union[float, Sequence[float]]
906-
) -> Dict[str, float]:
906+
) -> dict[str, float]:
907907
"""Converts an input value to GridDimensions.
908908
909909
Args:

python/ee/_helpers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import contextlib
1111
import json
1212
import sys
13-
from typing import Any, Dict, Iterator, Optional, TextIO, Union
13+
from typing import Any, Iterator, Optional, TextIO, Union
1414

1515
from google.auth import crypt
1616
from google.oauth2 import service_account
@@ -91,7 +91,7 @@ def call(
9191

9292
# pylint: disable-next=redefined-builtin
9393
def apply(
94-
func: Union[str, apifunction.ApiFunction], named_args: Dict[str, Any]
94+
func: Union[str, apifunction.ApiFunction], named_args: dict[str, Any]
9595
) -> computedobject.ComputedObject:
9696
"""Call a function with a dictionary of named arguments.
9797

0 commit comments

Comments
 (0)