Skip to content

Commit 576c25e

Browse files
dorellangcopybara-github
authored andcommitted
Replace 'Optional[...]' by '|' on type hints.
PiperOrigin-RevId: 658178117
1 parent 87e6c38 commit 576c25e

File tree

82 files changed

+465
-493
lines changed

Some content is hidden

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

82 files changed

+465
-493
lines changed

perfkitbenchmarker/app_service.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import logging
44
import threading
55
import time
6-
from typing import Any, Dict, List, Optional, Type, TypeVar
6+
from typing import Any, Dict, List, Type, TypeVar
77

88
from absl import flags
99
from perfkitbenchmarker import errors
@@ -108,7 +108,7 @@ def _GetOptionDecoderConstructions(cls) -> Dict[str, Any]:
108108
AppServiceChild = TypeVar('AppServiceChild', bound='BaseAppService')
109109

110110

111-
def GetAppServiceClass(service: str) -> Optional[Type[AppServiceChild]]:
111+
def GetAppServiceClass(service: str) -> Type[AppServiceChild] | None:
112112
"""Returns class of the given AppService.
113113
114114
Args:
@@ -150,7 +150,7 @@ def __init__(self, base_app_service_spec: BaseAppServiceSpec):
150150
self.region: str = base_app_service_spec.appservice_region
151151
self.backend: str = base_app_service_spec.appservice_backend
152152
self.builder: Any = None
153-
self.endpoint: Optional[str] = None
153+
self.endpoint: str | None = None
154154
self.poller: http_poller.HttpPoller = http_poller.HttpPoller()
155155
self.vm: virtual_machine.BaseVirtualMachine
156156
# update metadata

perfkitbenchmarker/cloud_harmony_util.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"""
55

66
import io
7-
from typing import Any, Dict, List, Optional
7+
from typing import Any, Dict, List
88

99
from absl import flags
1010
import pandas as pd
@@ -130,7 +130,7 @@ def ParseCsvResultsFromString(
130130
return results
131131

132132

133-
def GetCommonMetadata(custom_metadata: Optional[Dict[str, Any]] = None) -> str:
133+
def GetCommonMetadata(custom_metadata: Dict[str, Any] | None = None) -> str:
134134
"""Returns pkb metadata associated with this run as cloudharmony metadata.
135135
136136
Cloudharmony benchmarks take in benchmark setup configurations as inputs and

perfkitbenchmarker/configs/auto_registry.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import itertools
1616
import logging
1717
import typing
18-
from typing import Any, Optional
18+
from typing import Any
1919
from perfkitbenchmarker import errors
2020

2121

@@ -26,7 +26,7 @@
2626
def GetRegisteredClass(
2727
registry: dict[tuple[Any], type[T]],
2828
base_class: type[T],
29-
default_class: Optional[type[T]] = None,
29+
default_class: type[T] | None = None,
3030
**kwargs
3131
) -> type[T]:
3232
"""Returns the subclass with the corresponding attributes.
@@ -79,8 +79,8 @@ def GetRegisteredClass(
7979
def RegisterClass(
8080
registry: dict[tuple[Any], type[T]],
8181
cls: type[T],
82-
required_attrs: Optional[list[str]],
83-
cls_type: Optional[str],
82+
required_attrs: list[str] | None,
83+
cls_type: str | None,
8484
):
8585
"""Adds the class with its attributes to the registry.
8686

perfkitbenchmarker/configs/container_spec.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
configuration files.
1818
"""
1919

20-
from typing import Any, Optional
20+
from typing import Any
2121

2222
from absl import flags
2323
from perfkitbenchmarker import custom_virtual_machine_spec
@@ -40,7 +40,7 @@ class ContainerSpec(spec.BaseSpec):
4040
def __init__(
4141
self,
4242
component_full_name: str,
43-
flag_values: Optional[flags.FlagValues] = None,
43+
flag_values: flags.FlagValues | None = None,
4444
**kwargs: Any,
4545
):
4646
super().__init__(component_full_name, flag_values, **kwargs)
@@ -107,16 +107,16 @@ class ContainerRegistrySpec(spec.BaseSpec):
107107
def __init__(
108108
self,
109109
component_full_name: str,
110-
flag_values: Optional[flags.FlagValues] = None,
110+
flag_values: flags.FlagValues | None = None,
111111
**kwargs: Any,
112112
):
113113
super().__init__(component_full_name, flag_values=flag_values, **kwargs)
114-
self.spec: Optional[dict[str, Any]]
114+
self.spec: dict[str, Any] | None
115115
self.cloud: str
116116
registry_spec = getattr(self.spec, self.cloud, {})
117-
self.project: Optional[str] = registry_spec.get('project')
118-
self.zone: Optional[str] = registry_spec.get('zone')
119-
self.name: Optional[str] = registry_spec.get('name')
117+
self.project: str | None = registry_spec.get('project')
118+
self.zone: str | None = registry_spec.get('zone')
119+
self.name: str | None = registry_spec.get('name')
120120
self.cpus: float
121121
self.memory: int
122122
self.command: list[str]
@@ -240,7 +240,7 @@ def __init__(
240240
)
241241
self.vm_count: int
242242
self.vm_spec: spec.PerCloudConfigSpec
243-
self.sandbox_config: Optional[SandboxSpec]
243+
self.sandbox_config: SandboxSpec | None
244244

245245
@classmethod
246246
def _GetOptionDecoderConstructions(cls):

perfkitbenchmarker/configs/freeze_restore_spec.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
# limitations under the License.
1414
"""Benchmark-configurable options for freezing and restoring resources."""
1515

16-
from typing import Optional
17-
1816
from absl import flags
1917
from perfkitbenchmarker.configs import option_decoders
2018
from perfkitbenchmarker.configs import spec
@@ -42,7 +40,7 @@ class FreezeRestoreSpec(spec.BaseSpec):
4240
def __init__(
4341
self,
4442
component_full_name: str,
45-
flag_values: Optional[flags.FlagValues] = None,
43+
flag_values: flags.FlagValues | None = None,
4644
**kwargs
4745
):
4846
super().__init__(component_full_name, flag_values=flag_values, **kwargs)

perfkitbenchmarker/configs/spec.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import collections
1717
import logging
1818
import threading
19-
from typing import Any, Optional
19+
from typing import Any
2020

2121
from absl import flags
2222
from perfkitbenchmarker import errors
@@ -77,7 +77,7 @@ class BaseSpec(six.with_metaclass(BaseSpecMetaClass, object)):
7777
def __init__(
7878
self,
7979
component_full_name: str,
80-
flag_values: Optional[flags.FlagValues] = None,
80+
flag_values: flags.FlagValues | None = None,
8181
**kwargs: Any,
8282
):
8383
"""Initializes a BaseSpec.
@@ -200,7 +200,7 @@ def _DecodeAndInit(
200200
decoders: collections.OrderedDict[
201201
str, option_decoders.ConfigOptionDecoder
202202
],
203-
flag_values: Optional[flags.FlagValues],
203+
flag_values: flags.FlagValues | None,
204204
):
205205
"""Initializes spec attributes from provided config option values.
206206

perfkitbenchmarker/configs/vm_group_decoders.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414
"""Module containing a VM group spec and related decoders."""
15-
from typing import Optional
15+
1616
from perfkitbenchmarker import disk
1717
from perfkitbenchmarker import errors
1818
from perfkitbenchmarker import os_types
@@ -56,7 +56,7 @@ class VmGroupSpec(spec.BaseSpec):
5656
vm_count: int
5757
vm_spec: virtual_machine.BaseVmSpec
5858
vm_as_nfs: bool
59-
vm_as_nfs_disk_spec: Optional[disk.BaseNFSDiskSpec]
59+
vm_as_nfs_disk_spec: disk.BaseNFSDiskSpec | None
6060
placement_group_name: str
6161
cidr: str
6262

perfkitbenchmarker/container_service.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import os
3232
import re
3333
import time
34-
from typing import Any, Optional, Sequence
34+
from typing import Any, Sequence
3535

3636
from absl import flags
3737
import jinja2
@@ -166,7 +166,7 @@ class BaseContainer(resource.BaseResource):
166166
"""Class representing a single container."""
167167

168168
def __init__(
169-
self, container_spec: Optional[container_spec_lib.ContainerSpec] = None
169+
self, container_spec: container_spec_lib.ContainerSpec | None = None
170170
):
171171
# Hack to make container_spec a kwarg
172172
assert container_spec
@@ -175,7 +175,7 @@ def __init__(
175175
self.memory: int = container_spec.memory
176176
self.command: list[str] = container_spec.command
177177
self.image: str = container_spec.image
178-
self.ip_address: Optional[str] = None
178+
self.ip_address: str | None = None
179179

180180
def WaitForExit(self, timeout: int = 1200) -> dict[str, Any]:
181181
"""Gets the successfully finished container.
@@ -204,9 +204,9 @@ def __init__(self, container_spec: container_spec_lib.ContainerSpec):
204204
self.command: list[str] = container_spec.command
205205
self.image: str = container_spec.image
206206
self.container_port: int = container_spec.container_port
207-
self.ip_address: Optional[str] = None
208-
self.port: Optional[int] = None
209-
self.host_header: Optional[str] = None
207+
self.ip_address: str | None = None
208+
self.port: int | None = None
209+
self.host_header: str | None = None
210210

211211

212212
class ContainerImage:
@@ -396,14 +396,14 @@ def __init__(self, vm_config: virtual_machine.BaseVirtualMachine, name: str):
396396
self.machine_type = vm_config.machine_type
397397
self.name = NodePoolName(name)
398398
self.zone: str = vm_config.zone
399-
self.sandbox_config: Optional[container_spec_lib.SandboxSpec] = None
399+
self.sandbox_config: container_spec_lib.SandboxSpec | None = None
400400
self.num_nodes: int
401401
self.disk_type: str
402402
self.disk_size: int
403403
# Defined by google_kubernetes_engine
404-
self.max_local_disks: Optional[int]
405-
self.gpu_type: Optional[str]
406-
self.gpu_count: Optional[int]
404+
self.max_local_disks: int | None
405+
self.gpu_type: str | None
406+
self.gpu_count: int | None
407407
self.threads_per_core: int
408408
self.gce_tags: list[str]
409409
self.min_cpu_platform: str
@@ -631,7 +631,7 @@ def _GetPod(self) -> dict[str, Any]:
631631
self.ip_address = pod.get('status', {}).get('podIP')
632632
return pod
633633

634-
def WaitForExit(self, timeout: Optional[int] = None) -> dict[str, Any]:
634+
def WaitForExit(self, timeout: int | None = None) -> dict[str, Any]:
635635
"""Gets the finished running container."""
636636

637637
@vm_util.Retry(
@@ -881,7 +881,7 @@ def WaitForResource(
881881
self,
882882
resource_name: str,
883883
condition_name: str,
884-
namespace: Optional[str] = None,
884+
namespace: str | None = None,
885885
timeout: int = vm_util.DEFAULT_TIMEOUT,
886886
):
887887
"""Waits for a condition on a Kubernetes resource (eg: deployment, pod)."""
@@ -962,7 +962,7 @@ def CreateConfigMap(self, name: str, from_file_dir: str):
962962
)
963963

964964
def CreateServiceAccount(
965-
self, name: str, clusterrole: Optional[str] = None, namespace='default'
965+
self, name: str, clusterrole: str | None = None, namespace='default'
966966
):
967967
"""Create a k8s service account and cluster-role-binding."""
968968
RunKubectlCommand(
@@ -1101,11 +1101,11 @@ class KubernetesEvent:
11011101
resource: KubernetesEventResource
11021102
message: str
11031103
# Reason is actually more of a machine readable message.
1104-
reason: Optional[str]
1104+
reason: str | None
11051105
timestamp: float
11061106

11071107
@classmethod
1108-
def FromDict(cls, yaml_data: dict[str, Any]) -> Optional['KubernetesEvent']:
1108+
def FromDict(cls, yaml_data: dict[str, Any]) -> 'KubernetesEvent | None':
11091109
"""Parse Kubernetes Event YAML output."""
11101110
if 'message' not in yaml_data:
11111111
return

perfkitbenchmarker/disk_strategies.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import json
2525
import logging
2626
import time
27-
from typing import Any, Optional, Union
27+
from typing import Any, Union
2828

2929
from absl import flags
3030
from perfkitbenchmarker import background_tasks
@@ -252,7 +252,7 @@ def __init__(
252252
self,
253253
vm,
254254
disk_spec: disk.BaseDiskSpec,
255-
unmanaged_nfs_service: Optional[nfs_service.BaseNfsService] = None,
255+
unmanaged_nfs_service: nfs_service.BaseNfsService | None = None,
256256
):
257257
super().__init__(vm, disk_spec)
258258
if unmanaged_nfs_service:

0 commit comments

Comments
 (0)