Skip to content

Commit d0a54b9

Browse files
committed
Replace Optional with | None
1 parent 93e4bec commit d0a54b9

30 files changed

+101
-105
lines changed

bin/cleanup/cleanup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ def cleanup_client(
379379
gcp_api_manager,
380380
gcp_service_account,
381381
*,
382-
suffix: Optional[str] = "",
382+
suffix: str | None = "",
383383
):
384384
deployment_name = xds_flags.CLIENT_NAME.value
385385
if suffix:

framework/bootstrap_generator_testcase.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def initTrafficDirectorManager(cls) -> TrafficDirectorManager:
127127

128128
@classmethod
129129
def initKubernetesServerRunner(
130-
cls, *, td_bootstrap_image: Optional[str] = None
130+
cls, *, td_bootstrap_image: str | None = None
131131
) -> KubernetesServerRunner:
132132
if not td_bootstrap_image:
133133
td_bootstrap_image = cls.td_bootstrap_image
@@ -165,7 +165,7 @@ def startTestServer(
165165
return test_server
166166

167167
def initKubernetesClientRunner(
168-
self, td_bootstrap_image: Optional[str] = None
168+
self, td_bootstrap_image: str | None = None
169169
) -> KubernetesClientRunner:
170170
if not td_bootstrap_image:
171171
td_bootstrap_image = self.td_bootstrap_image

framework/helpers/datetime.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def datetime_suffix(*, seconds: bool = False) -> str:
5757
return utc_now().strftime("%Y%m%d-%H%M" + ("%S" if seconds else ""))
5858

5959

60-
def ago(date_from: datetime.datetime, now: Optional[datetime.datetime] = None):
60+
def ago(date_from: datetime.datetime, now: datetime.datetime | None = None):
6161
if not now:
6262
now = utc_now()
6363

framework/helpers/grpc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def from_response(
7777
) -> "PrettyStatsPerMethod":
7878
stats: dict[str, int] = dict()
7979
for status_int, count in method_stats.result.items():
80-
status: Optional[grpc.StatusCode] = status_from_int(status_int)
80+
status: grpc.StatusCode | None = status_from_int(status_int)
8181
status_formatted = status_pretty(status) if status else "None"
8282
stats[status_formatted] = count
8383
return PrettyStatsPerMethod(

framework/helpers/highlighter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class Highlighter:
6363
formatter: Formatter
6464
lexer: Lexer
6565
color: bool
66-
color_style: Optional[str] = None
66+
color_style: str | None = None
6767

6868
def __init__(
6969
self,

framework/helpers/retryers.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@
4141

4242
def _build_retry_conditions(
4343
*,
44-
retry_on_exceptions: Optional[_ExceptionClasses] = None,
45-
check_result: Optional[CheckResultFn] = None,
44+
retry_on_exceptions: _ExceptionClasses | None = None,
45+
check_result: CheckResultFn | None = None,
4646
) -> List[retry_base]:
4747
# Retry on all exceptions by default
4848
if retry_on_exceptions is None:
@@ -63,10 +63,10 @@ def exponential_retryer_with_timeout(
6363
wait_min: timedelta,
6464
wait_max: timedelta,
6565
timeout: timedelta,
66-
retry_on_exceptions: Optional[_ExceptionClasses] = None,
67-
check_result: Optional[CheckResultFn] = None,
68-
logger: Optional[logging.Logger] = None,
69-
log_level: Optional[int] = logging.DEBUG,
66+
retry_on_exceptions: _ExceptionClasses | None = None,
67+
check_result: CheckResultFn | None = None,
68+
logger: logging.Logger | None = None,
69+
log_level: int | None = logging.DEBUG,
7070
error_note: str = "",
7171
) -> Retrying:
7272
if logger is None:
@@ -95,11 +95,11 @@ def constant_retryer(
9595
*,
9696
wait_fixed: timedelta,
9797
attempts: int = 0,
98-
timeout: Optional[timedelta] = None,
99-
retry_on_exceptions: Optional[_ExceptionClasses] = None,
100-
check_result: Optional[CheckResultFn] = None,
101-
logger: Optional[logging.Logger] = None,
102-
log_level: Optional[int] = logging.DEBUG,
98+
timeout: timedelta | None = None,
99+
retry_on_exceptions: _ExceptionClasses | None = None,
100+
check_result: CheckResultFn | None = None,
101+
logger: logging.Logger | None = None,
102+
log_level: int | None = logging.DEBUG,
103103
error_note: str = "",
104104
) -> Retrying:
105105
if logger is None:
@@ -134,7 +134,7 @@ def constant_retryer(
134134

135135
def _on_error_callback(
136136
*,
137-
timeout: Optional[timedelta] = None,
137+
timeout: timedelta | None = None,
138138
attempts: int = 0,
139139
check_result: Optional[CheckResultFn] = None,
140140
error_note: str = "",

framework/infrastructure/gcp/api.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888

8989
class GcpApiManager:
9090
# The previous value of googleapiclient.model.dump_request_response.
91-
_dump_req_resp: Optional[bool] = None
91+
_dump_req_resp: bool | None = None
9292

9393
def __init__(
9494
self,
@@ -263,8 +263,8 @@ def _build_from_discovery_v2(
263263
api_name,
264264
version,
265265
*,
266-
api_key: Optional[str] = None,
267-
visibility_labels: Optional[List] = None,
266+
api_key: str | None = None,
267+
visibility_labels: List | None = None,
268268
):
269269
params = {}
270270
if api_key:
@@ -441,7 +441,7 @@ def _execute(
441441
self,
442442
request: HttpRequest,
443443
*,
444-
num_retries: Optional[int] = _GCP_API_RETRIES,
444+
num_retries: int | None = _GCP_API_RETRIES,
445445
) -> Dict[str, Any]:
446446
"""Execute the immediate request.
447447
@@ -515,7 +515,7 @@ def wait_for_operation(
515515
class GcpStandardCloudApiResource(GcpProjectApiResource, metaclass=abc.ABCMeta):
516516
GLOBAL_LOCATION = "global"
517517

518-
def parent(self, location: Optional[str] = GLOBAL_LOCATION):
518+
def parent(self, location: str | None = GLOBAL_LOCATION):
519519
if location is None:
520520
location = self.GLOBAL_LOCATION
521521
return f"projects/{self.project}/locations/{location}"

framework/infrastructure/gcp/compute.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def __init__(
6060
self,
6161
api_manager: gcp.api.GcpApiManager,
6262
project: str,
63-
gfe_debug_header: Optional[str] = None,
63+
gfe_debug_header: str | None = None,
6464
version: str = "v1",
6565
):
6666
super().__init__(api_manager.compute(version), project)
@@ -80,7 +80,7 @@ def create_health_check(
8080
name: str,
8181
protocol: HealthCheckProtocol,
8282
*,
83-
port: Optional[int] = None,
83+
port: int | None = None,
8484
) -> "GcpResource":
8585
if protocol is self.HealthCheckProtocol.TCP:
8686
health_check_field = "tcpHealthCheck"
@@ -146,11 +146,11 @@ def create_backend_service_traffic_director(
146146
self,
147147
name: str,
148148
health_check: "GcpResource",
149-
affinity_header: Optional[str] = None,
150-
protocol: Optional[BackendServiceProtocol] = None,
151-
subset_size: Optional[int] = None,
152-
locality_lb_policies: Optional[List[dict]] = None,
153-
outlier_detection: Optional[dict] = None,
149+
affinity_header: str | None = None,
150+
protocol: BackendServiceProtocol | None = None,
151+
subset_size: int | None = None,
152+
locality_lb_policies: List[dict] | None = None,
153+
outlier_detection: dict | None = None,
154154
enable_dualstack: bool = False,
155155
) -> "GcpResource":
156156
if not isinstance(protocol, self.BackendServiceProtocol):
@@ -201,9 +201,9 @@ def backend_service_patch_backends(
201201
self,
202202
backend_service,
203203
backends,
204-
max_rate_per_endpoint: Optional[int] = None,
204+
max_rate_per_endpoint: int | None = None,
205205
*,
206-
circuit_breakers: Optional[dict[str, int]] = None,
206+
circuit_breakers: dict[str, int] | None = None,
207207
):
208208
if max_rate_per_endpoint is None:
209209
max_rate_per_endpoint = 5
@@ -244,7 +244,7 @@ def create_url_map(
244244
matcher_name: str,
245245
src_hosts,
246246
dst_default_backend_service: "GcpResource",
247-
dst_host_rule_match_backend_service: Optional["GcpResource"] = None,
247+
dst_host_rule_match_backend_service: "GcpResource" | None = None,
248248
) -> "GcpResource":
249249
if dst_host_rule_match_backend_service is None:
250250
dst_host_rule_match_backend_service = dst_default_backend_service

framework/infrastructure/gcp/iam.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ class Binding:
131131

132132
role: str
133133
members: FrozenSet[str]
134-
condition: Optional[Expr] = None
134+
condition: Expr | None = None
135135

136136
@classmethod
137137
def from_response(cls, response: Dict[str, Any]) -> "Policy.Binding":

framework/infrastructure/gcp/network_services.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ class EndpointPolicy:
3737
endpoint_matcher: dict
3838
update_time: str
3939
create_time: str
40-
http_filters: Optional[dict] = None
41-
server_tls_policy: Optional[str] = None
40+
http_filters: dict | None = None
41+
server_tls_policy: str | None = None
4242

4343
@classmethod
4444
def from_response(

framework/infrastructure/k8s.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,7 @@ def delete_pod(
733733
self,
734734
name: str,
735735
*,
736-
grace_period: Optional[_timedelta] = DELETE_GRACE_PERIOD,
736+
grace_period: _timedelta | None = DELETE_GRACE_PERIOD,
737737
) -> None:
738738
delete_options = client.V1DeleteOptions(propagation_policy="Foreground")
739739

@@ -872,8 +872,8 @@ def wait_for_service_account_deleted(
872872

873873
def wait_for_namespace_deleted(
874874
self,
875-
timeout_sec: Optional[int] = None,
876-
wait_sec: Optional[int] = None,
875+
timeout_sec: int | None = None,
876+
wait_sec: int | None = None,
877877
) -> None:
878878
if timeout_sec is None:
879879
if self.wait_for_namespace_deleted_timeout_sec is not None:
@@ -1076,8 +1076,8 @@ def port_forward_pod(
10761076
self,
10771077
pod: V1Pod,
10781078
remote_port: int,
1079-
local_port: Optional[int] = None,
1080-
local_address: Optional[str] = None,
1079+
local_port: int | None = None,
1080+
local_address: str | None = None,
10811081
) -> k8s_port_forwarder.PortForwarder:
10821082
destination = f"pod/{pod.metadata.name}"
10831083
logger.info(
@@ -1138,7 +1138,7 @@ def pretty_format_status(
11381138
return "No data"
11391139

11401140
result = []
1141-
metadata: Optional[V1ObjectMeta] = None
1141+
metadata: V1ObjectMeta | None = None
11421142
if isinstance(getattr(k8s_object, "metadata", None), V1ObjectMeta):
11431143
# Parse the name if present.
11441144
metadata: V1ObjectMeta = k8s_object.metadata

framework/infrastructure/k8s_internal/k8s_port_forwarder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def __init__(
3333
namespace: str,
3434
destination: str,
3535
remote_port: int,
36-
local_port: Optional[int] = None,
36+
local_port: int | None = None,
3737
local_address: Optional[str] = None,
3838
):
3939
self.context = context

framework/infrastructure/traffic_director.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ class TrafficDirectorManager: # pylint: disable=too-many-public-methods
8888
alternative_backends: set[NegGcpResource]
8989

9090
# Backend Serivices
91-
backend_service: Optional[GcpResource] = None
92-
affinity_backend_service: Optional[GcpResource] = None
93-
alternative_backend_service: Optional[GcpResource] = None
91+
backend_service: GcpResource | None = None
92+
affinity_backend_service: GcpResource | None = None
93+
alternative_backend_service: GcpResource | None = None
9494

9595
# TODO(sergiitk): move these flags to backend service dataclass
9696
backend_service_protocol: BackendServiceProtocol = _BackendUnset
@@ -127,19 +127,19 @@ def __init__(
127127
self.enable_dualstack: bool = enable_dualstack
128128

129129
# Managed resources
130-
self.health_check: Optional[GcpResource] = None
131-
self.url_map: Optional[GcpResource] = None
132-
self.alternative_url_map: Optional[GcpResource] = None
133-
self.firewall_rule: Optional[GcpResource] = None
134-
self.firewall_rule_ipv6: Optional[GcpResource] = None
135-
self.target_proxy: Optional[GcpResource] = None
136-
self.target_proxy_ipv6: Optional[GcpResource] = None
130+
self.health_check: GcpResource | None = None
131+
self.url_map: GcpResource | None = None
132+
self.alternative_url_map: GcpResource | None = None
133+
self.firewall_rule: GcpResource | None = None
134+
self.firewall_rule_ipv6: GcpResource | None = None
135+
self.target_proxy: GcpResource | None = None
136+
self.target_proxy_ipv6: GcpResource | None = None
137137
# TODO(sergiitk): remove this flag once target proxy resource loaded
138138
self.target_proxy_is_http: bool = False
139-
self.alternative_target_proxy: Optional[GcpResource] = None
140-
self.forwarding_rule: Optional[GcpResource] = None
141-
self.forwarding_rule_ipv6: Optional[GcpResource] = None
142-
self.alternative_forwarding_rule: Optional[GcpResource] = None
139+
self.alternative_target_proxy: GcpResource | None = None
140+
self.forwarding_rule: GcpResource | None = None
141+
self.forwarding_rule_ipv6: GcpResource | None = None
142+
self.alternative_forwarding_rule: GcpResource | None = None
143143

144144
# Backends.
145145
self.backends = set()
@@ -155,8 +155,8 @@ def setup_for_grpc(
155155
service_host,
156156
service_port,
157157
*,
158-
backend_protocol: Optional[BackendServiceProtocol] = _BackendGRPC,
159-
health_check_port: Optional[int] = None,
158+
backend_protocol: BackendServiceProtocol | None = _BackendGRPC,
159+
health_check_port: int | None = None,
160160
):
161161
self.setup_backend_for_grpc(
162162
protocol=backend_protocol, health_check_port=health_check_port
@@ -166,8 +166,8 @@ def setup_for_grpc(
166166
def setup_backend_for_grpc(
167167
self,
168168
*,
169-
protocol: Optional[BackendServiceProtocol] = _BackendGRPC,
170-
health_check_port: Optional[int] = None,
169+
protocol: BackendServiceProtocol | None = _BackendGRPC,
170+
health_check_port: int | None = None,
171171
):
172172
self.create_health_check(port=health_check_port)
173173
self.create_backend_service(protocol)
@@ -211,8 +211,8 @@ def make_resource_name(self, name: str) -> str:
211211
def create_health_check(
212212
self,
213213
*,
214-
protocol: Optional[HealthCheckProtocol] = _HealthCheckGRPC,
215-
port: Optional[int] = None,
214+
protocol: HealthCheckProtocol | None = _HealthCheckGRPC,
215+
port: int | None = None,
216216
):
217217
if self.health_check:
218218
raise ValueError(
@@ -240,8 +240,8 @@ def delete_health_check(self, force=False):
240240

241241
def create_backend_service(
242242
self,
243-
protocol: Optional[BackendServiceProtocol] = _BackendGRPC,
244-
subset_size: Optional[int] = None,
243+
protocol: BackendServiceProtocol | None = _BackendGRPC,
244+
subset_size: int | None = None,
245245
affinity_header: Optional[str] = None,
246246
locality_lb_policies: Optional[List[dict]] = None,
247247
outlier_detection: Optional[dict] = None,

framework/rpc/grpc_channelz.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,7 @@
5858
class ChannelzServiceClient(framework.rpc.grpc.GrpcClientHelper):
5959
stub: channelz_pb2_grpc.ChannelzStub
6060

61-
def __init__(
62-
self, channel: grpc.Channel, *, log_target: Optional[str] = ""
63-
):
61+
def __init__(self, channel: grpc.Channel, *, log_target: str | None = ""):
6462
super().__init__(
6563
channel, channelz_pb2_grpc.ChannelzStub, log_target=log_target
6664
)

framework/rpc/grpc_csds.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ class CsdsClient(framework.rpc.grpc.GrpcClientHelper):
163163
DEFAULT_RPC_DEADLINE: Final[dt.timedelta] = dt.timedelta(seconds=30)
164164

165165
def __init__(
166-
self, channel: grpc.Channel, *, log_target: Optional[str] = ""
166+
self, channel: grpc.Channel, *, log_target: str | None = ""
167167
) -> None:
168168
super().__init__(channel, self.STUB_CLASS, log_target=log_target)
169169

framework/rpc/grpc_testing.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,7 @@ class LoadBalancerStatsServiceClient(framework.rpc.grpc.GrpcClientHelper):
135135
STATS_PARTIAL_RESULTS_TIMEOUT_SEC = 1200
136136
STATS_ACCUMULATED_RESULTS_TIMEOUT_SEC = 600
137137

138-
def __init__(
139-
self, channel: grpc.Channel, *, log_target: Optional[str] = ""
140-
):
138+
def __init__(self, channel: grpc.Channel, *, log_target: str | None = ""):
141139
super().__init__(
142140
channel,
143141
test_pb2_grpc.LoadBalancerStatsServiceStub,

0 commit comments

Comments
 (0)