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(

0 commit comments

Comments
 (0)