Skip to content

Commit dc7b5b0

Browse files
authored
[Gemini] Migrate all remaining uses of typing types with built-in equivalents (#38334)
* [Gemini] Migrate all remaining uses of typing types with built-in equivalents * Fix comment type hint imports * move noqa * trigger postcommit for extra validation * remove weird double import * restore import in example * other misc weird import changes * enable UP006 by default * yapf * fix gen_xlang_wrappers.py * Fix gen_managed_doc.py * last yapf fixes * fix pretty_type for built-in generics * strip nested typing module tags * restore type checking import in worker_handlers.py
1 parent 674873d commit dc7b5b0

188 files changed

Lines changed: 883 additions & 1171 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"comment": "Modify this file in a trivial way to cause this test suite to run.",
33
"pr": "38069",
4-
"modification": 40
4+
"modification": 41
55
}

sdks/python/apache_beam/coders/coder_impl.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"""
3131
# pytype: skip-file
3232

33+
# ruff: noqa: UP006
3334
import dataclasses
3435
import decimal
3536
import enum

sdks/python/apache_beam/coders/coders.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,9 @@
4343
from typing import TYPE_CHECKING
4444
from typing import Any
4545
from typing import Callable
46-
from typing import Dict
4746
from typing import Iterable
48-
from typing import List
4947
from typing import Optional
5048
from typing import Sequence
51-
from typing import Tuple
52-
from typing import Type
5349
from typing import TypeVar
5450
from typing import overload
5551

@@ -68,7 +64,6 @@
6864
from apache_beam.utils import windowed_value
6965

7066
if TYPE_CHECKING:
71-
from apache_beam.coders.typecoders import CoderRegistry
7267
from apache_beam.runners.pipeline_context import PipelineContext
7368

7469
# pylint: disable=wrong-import-order, wrong-import-position, ungrouped-imports
@@ -122,7 +117,7 @@
122117
T = TypeVar('T')
123118
CoderT = TypeVar('CoderT', bound='Coder')
124119
ProtoCoderT = TypeVar('ProtoCoderT', bound='ProtoCoder')
125-
ConstructorFn = Callable[[Optional[Any], List['Coder'], 'PipelineContext'], Any]
120+
ConstructorFn = Callable[[Optional[Any], list['Coder'], 'PipelineContext'], Any]
126121

127122

128123
def serialize_coder(coder):
@@ -1508,7 +1503,7 @@ def __hash__(self):
15081503

15091504
class _OrderedUnionCoder(FastCoder):
15101505
def __init__(
1511-
self, *coder_types: Tuple[type, Coder], fallback_coder: Optional[Coder]):
1506+
self, *coder_types: tuple[type, Coder], fallback_coder: Optional[Coder]):
15121507
self._coder_types = coder_types
15131508
self._fallback_coder = fallback_coder
15141509

@@ -1816,7 +1811,7 @@ def _create_impl(self):
18161811
def to_type_hint(self):
18171812
return self._window_coder.to_type_hint()
18181813

1819-
def _get_component_coders(self) -> List[Coder]:
1814+
def _get_component_coders(self) -> list[Coder]:
18201815
return [self._window_coder]
18211816

18221817
def is_deterministic(self) -> bool:

sdks/python/apache_beam/coders/coders_test_common.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import unittest
3232
from decimal import Decimal
3333
from typing import Any
34-
from typing import List
3534
from typing import NamedTuple
3635

3736
import pytest
@@ -145,7 +144,7 @@ class CodersTest(unittest.TestCase):
145144
# nested and unnested context.
146145

147146
# Common test values representing Python's built-in types.
148-
test_values_deterministic: List[Any] = [
147+
test_values_deterministic: list[Any] = [
149148
None,
150149
1,
151150
-1,

sdks/python/apache_beam/coders/observable_test.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
import logging
2222
import unittest
23-
from typing import List
2423
from typing import Optional
2524

2625
from apache_beam.coders import observable
@@ -29,7 +28,7 @@
2928
class ObservableMixinTest(unittest.TestCase):
3029
observed_count = 0
3130
observed_sum = 0
32-
observed_keys: List[Optional[str]] = []
31+
observed_keys: list[Optional[str]] = []
3332

3433
def observer(self, value, key=None):
3534
self.observed_count += 1

sdks/python/apache_beam/coders/row_coder_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
("name", str),
4444
("age", np.int32),
4545
("address", typing.Optional[str]),
46-
("aliases", typing.List[str]),
46+
("aliases", list[str]),
4747
("knows_javascript", bool),
4848
("payload", typing.Optional[bytes]),
4949
("custom_metadata", typing.Mapping[str, int]),
@@ -53,7 +53,7 @@
5353
NullablePerson = typing.NamedTuple(
5454
"NullablePerson",
5555
[("name", typing.Optional[str]), ("age", np.int32),
56-
("address", typing.Optional[str]), ("aliases", typing.List[str]),
56+
("address", typing.Optional[str]), ("aliases", list[str]),
5757
("knows_javascript", bool), ("payload", typing.Optional[bytes]),
5858
("custom_metadata", typing.Mapping[str, int]),
5959
("favorite_time", typing.Optional[Timestamp]),

sdks/python/apache_beam/coders/slow_stream.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,14 @@
2222
# pytype: skip-file
2323

2424
import struct
25-
from typing import List
2625

2726

2827
class OutputStream(object):
2928
"""For internal use only; no backwards-compatibility guarantees.
3029
3130
A pure Python implementation of stream.OutputStream."""
3231
def __init__(self):
33-
self.data: List[bytes] = []
32+
self.data: list[bytes] = []
3433
self.byte_count = 0
3534

3635
def write(self, b: bytes, nested: bool = False) -> None:

sdks/python/apache_beam/coders/standard_coders_test.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
2626
import sys
2727
import unittest
2828
from copy import deepcopy
29-
from typing import Dict
30-
from typing import Tuple
3129

3230
import numpy as np
3331
import yaml
@@ -283,7 +281,7 @@ def json_value_parser(self, coder_spec):
283281
# Used when --fix is passed.
284282

285283
fix = False
286-
to_fix: Dict[Tuple[int, bytes], bytes] = {}
284+
to_fix: dict[tuple[int, bytes], bytes] = {}
287285

288286
@classmethod
289287
def tearDownClass(cls):

sdks/python/apache_beam/coders/typecoders.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,7 @@ def MakeXyzs(v):
6666

6767
# pytype: skip-file
6868
from typing import Any
69-
from typing import Dict
7069
from typing import Iterable
71-
from typing import List
72-
from typing import Type
7370

7471
from apache_beam.coders import coders
7572
from apache_beam.typehints import typehints
@@ -81,8 +78,8 @@ def MakeXyzs(v):
8178
class CoderRegistry(object):
8279
"""A coder registry for typehint/coder associations."""
8380
def __init__(self, fallback_coder=None):
84-
self._coders: Dict[Any, Type[coders.Coder]] = {}
85-
self.custom_types: List[Any] = []
81+
self._coders: dict[Any, type[coders.Coder]] = {}
82+
self.custom_types: list[Any] = []
8683
self.register_standard_coders(fallback_coder)
8784

8885
def register_standard_coders(self, fallback_coder):
@@ -110,7 +107,7 @@ def register_fallback_coder(self, fallback_coder):
110107

111108
def _register_coder_internal(
112109
self, typehint_type: Any,
113-
typehint_coder_class: Type[coders.Coder]) -> None:
110+
typehint_coder_class: type[coders.Coder]) -> None:
114111
self._coders[typehint_type] = typehint_coder_class
115112

116113
@staticmethod
@@ -123,7 +120,7 @@ def _normalize_typehint_type(typehint_type):
123120

124121
def register_coder(
125122
self, typehint_type: Any,
126-
typehint_coder_class: Type[coders.Coder]) -> None:
123+
typehint_coder_class: type[coders.Coder]) -> None:
127124
"""
128125
Register a user type with a coder.
129126
@@ -244,7 +241,7 @@ class FirstOf(object):
244241
"""For internal use only; no backwards-compatibility guarantees.
245242
246243
A class used to get the first matching coder from a list of coders."""
247-
def __init__(self, coders: Iterable[Type[coders.Coder]]) -> None:
244+
def __init__(self, coders: Iterable[type[coders.Coder]]) -> None:
248245
self._coders = coders
249246

250247
def from_type_hint(self, typehint, registry):

sdks/python/apache_beam/dataframe/frame_base.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
from inspect import unwrap
2626
from typing import Any
2727
from typing import Optional
28-
from typing import Tuple
2928
from typing import Union
3029

3130
import pandas as pd
@@ -163,7 +162,7 @@ def binop(self, other):
163162
DeferredBase._pandas_type_map[None] = _DeferredScalar
164163

165164

166-
def name_and_func(method: Union[str, Callable]) -> Tuple[str, Callable]:
165+
def name_and_func(method: Union[str, Callable]) -> tuple[str, Callable]:
167166
"""For the given method name or method, return the method name and the method
168167
itself.
169168

0 commit comments

Comments
 (0)