Skip to content

Commit d9c547f

Browse files
authored
chore(code) remove Optional (#272)
1 parent 0311a76 commit d9c547f

33 files changed

Lines changed: 206 additions & 208 deletions

.github/workflows/pythonpackage.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ jobs:
3434
- name: Install project
3535
run: poetry install --no-interaction
3636

37-
- name: Launch tests
38-
run: poetry run pytest
39-
40-
- name: Launch Linting
37+
- name: Linting
4138
run: poetry run flake8 --show-source --statistics
39+
40+
- name: Tests
41+
run: poetry run pytest

cloudfoundry_client/client.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from pathlib import Path
33
import json
44
from http import HTTPStatus
5-
from typing import Optional
65

76
import requests
87
from oauth2_client.credentials_manager import CredentialManager, ServiceInformation
@@ -56,8 +55,8 @@ def __init__(
5655
api_v3_url: str,
5756
authorization_endpoint: str,
5857
api_endpoint: str,
59-
doppler_endpoint: Optional[str],
60-
log_stream_endpoint: Optional[str],
58+
doppler_endpoint: str | None,
59+
log_stream_endpoint: str | None,
6160
):
6261
self._api_v2_url = api_v2_url
6362
self._api_v3_url = api_v3_url
@@ -67,11 +66,11 @@ def __init__(
6766
self.log_stream_endpoint = log_stream_endpoint
6867

6968
@property
70-
def api_v2_url(self) -> Optional[str]:
69+
def api_v2_url(self) -> str | None:
7170
return self._api_v2_url
7271

7372
@property
74-
def api_v3_url(self) -> Optional[str]:
73+
def api_v3_url(self) -> str | None:
7574
return self._api_v3_url
7675

7776

@@ -226,7 +225,7 @@ def rlpgateway(self):
226225
else:
227226
return self._rlpgateway
228227

229-
def _get_info(self, target_endpoint: str, proxy: Optional[dict] = None, verify: bool = True) -> Info:
228+
def _get_info(self, target_endpoint: str, proxy: dict | None = None, verify: bool = True) -> Info:
230229
root_response = CloudFoundryClient._check_response(
231230
requests.get("%s/" % target_endpoint, proxies=proxy if proxy is not None else dict(http="", https=""), verify=verify)
232231
)
@@ -247,7 +246,7 @@ def _get_info(self, target_endpoint: str, proxy: Optional[dict] = None, verify:
247246
)
248247

249248
@staticmethod
250-
def build_from_cf_config(config_path: Optional[str] = None, **kwargs) -> 'CloudFoundryClient':
249+
def build_from_cf_config(config_path: str | None = None, **kwargs) -> 'CloudFoundryClient':
251250
config = Path(config_path) if config_path else Path.home() / '.cf/config.json'
252251
try:
253252
with open(config) as f:
@@ -318,7 +317,7 @@ def _grant_client_credentials_request(self) -> dict:
318317
client_secret=self.service_information.client_secret,
319318
)
320319

321-
def get(self, url: str, params: Optional[dict] = None, **kwargs) -> Response:
320+
def get(self, url: str, params: dict | None = None, **kwargs) -> Response:
322321
response = super(CloudFoundryClient, self).get(url, params, **kwargs)
323322
CloudFoundryClient._log_request("GET", url, response)
324323
return CloudFoundryClient._check_response(response)

cloudfoundry_client/common_objects.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import json
2-
from typing import Callable, TypeVar, Generic, List, Optional
2+
from typing import Callable, TypeVar, Generic, List
33

44

55
class Request(dict):
@@ -21,7 +21,7 @@ def __init__(self, *args, **kwargs):
2121
class Pagination(Generic[ENTITY]):
2222
def __init__(self, first_page: JsonObject,
2323
total_result: int,
24-
next_page_loader: Callable[[JsonObject], Optional[JsonObject]],
24+
next_page_loader: Callable[[JsonObject], JsonObject | None],
2525
resources_accessor: Callable[[JsonObject], List[JsonObject]],
2626
instance_creator: Callable[[JsonObject], ENTITY]):
2727
self._first_page = first_page

cloudfoundry_client/doppler/websocket_envelope_reader.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import ssl
2-
from typing import Callable, Optional, Tuple
2+
from typing import Callable, Tuple
33

44
import websocket
55

@@ -10,9 +10,9 @@ def __init__(
1010
url,
1111
access_token_provider: Callable[[], str],
1212
verify_ssl: bool = True,
13-
proxy_host: Optional[str] = None,
14-
proxy_port: Optional[int] = None,
15-
proxy_auth: Optional[Tuple[str, str]] = None,
13+
proxy_host: str | None = None,
14+
proxy_port: int | None = None,
15+
proxy_auth: Tuple[str, str] | None = None,
1616
):
1717
if not verify_ssl:
1818
self._ws = websocket.WebSocket(sslopt=dict(cert_reqs=ssl.CERT_NONE))

cloudfoundry_client/networking/entities.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import logging
22
from functools import reduce
3-
from typing import Callable, List, Tuple, Any, Optional, Generator, TYPE_CHECKING
3+
from typing import Callable, List, Tuple, Any, Generator, TYPE_CHECKING
44
from urllib.parse import quote
55

66
from requests import Response
@@ -40,7 +40,7 @@ class EntityManager(object):
4040
list_multi_parameters = ["order-by"]
4141

4242
def __init__(
43-
self, target_endpoint: str, client: "CloudFoundryClient", entity_uri: str, entity_builder: Optional[EntityBuilder] = None
43+
self, target_endpoint: str, client: "CloudFoundryClient", entity_uri: str, entity_builder: EntityBuilder | None = None
4444
):
4545
self.target_endpoint = target_endpoint
4646
self.entity_uri = entity_uri
@@ -50,7 +50,7 @@ def __init__(
5050
)
5151

5252
def _list(
53-
self, requested_path: str, entity_builder: Optional[EntityBuilder] = None, **kwargs
53+
self, requested_path: str, entity_builder: EntityBuilder | None = None, **kwargs
5454
) -> Generator[Entity, None, None]:
5555
url_requested = self._get_url_filtered("%s%s" % (self.target_endpoint, requested_path), **kwargs)
5656
response = self.client.get(url_requested)
@@ -68,7 +68,7 @@ def _remove(self, resource_id: str, **kwargs):
6868
url = "%s%s/%s" % (self.target_endpoint, self.entity_uri, resource_id)
6969
self._delete(url, **kwargs)
7070

71-
def _post(self, url: str, data: Optional[dict] = None, **kwargs):
71+
def _post(self, url: str, data: dict | None = None, **kwargs):
7272
response = self.client.post(url, json=data, **kwargs)
7373
_logger.debug("POST - %s - %s", url, response.text)
7474
return self._read_response(response)
@@ -83,13 +83,13 @@ def __iter__(self) -> Generator[Entity, None, None]:
8383
def list(self, **kwargs) -> Generator[Entity, None, None]:
8484
return self._list(self.entity_uri, **kwargs)
8585

86-
def get_first(self, **kwargs) -> Optional[Entity]:
86+
def get_first(self, **kwargs) -> Entity | None:
8787
kwargs.setdefault("results-per-page", 1)
8888
for entity in self._list(self.entity_uri, **kwargs):
8989
return entity
9090
return None
9191

92-
def _read_response(self, response: Response, other_entity_builder: Optional[EntityBuilder] = None):
92+
def _read_response(self, response: Response, other_entity_builder: EntityBuilder | None = None):
9393
entity_builder = self._get_entity_builder(other_entity_builder)
9494
result = response.json(object_pairs_hook=JsonObject)
9595
return entity_builder(list(result.items()))
@@ -98,7 +98,7 @@ def _read_response(self, response: Response, other_entity_builder: Optional[Enti
9898
def _request(**mandatory_parameters) -> Request:
9999
return Request(**mandatory_parameters)
100100

101-
def _get_entity_builder(self, entity_builder: Optional[EntityBuilder]) -> EntityBuilder:
101+
def _get_entity_builder(self, entity_builder: EntityBuilder | None) -> EntityBuilder:
102102
if entity_builder is None:
103103
return self.entity_builder
104104
else:

cloudfoundry_client/operations/push/file_helper.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
import os
33
import stat
44
import zipfile
5-
from typing import Callable, Optional, Generator, Tuple, List
5+
from typing import Callable, Generator, Tuple, List
66

77

88
class FileHelper(object):
99
@staticmethod
10-
def zip(file_location: str, directory_path: str, accept: Optional[Callable[[str], bool]] = None):
10+
def zip(file_location: str, directory_path: str, accept: Callable[[str], bool] | None = None):
1111
with zipfile.ZipFile(file_location, "w", zipfile.ZIP_DEFLATED) as archive_out:
1212
for dir_path, file_names in FileHelper.walk(directory_path):
1313
dir_full_location = os.path.join(directory_path, dir_path)

cloudfoundry_client/operations/push/push.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import shutil
66
import tempfile
77
import time
8-
from typing import Tuple, List, Dict, Optional
8+
from typing import Tuple, List, Dict
99

1010
from cloudfoundry_client.client import CloudFoundryClient
1111
from cloudfoundry_client.operations.push.cf_ignore import CfIgnore
@@ -96,7 +96,7 @@ def _build_request_from_manifest(self, app_manifest: dict) -> dict:
9696
return request
9797

9898
@staticmethod
99-
def _merge_environment(app: Optional[Entity], app_manifest: dict) -> dict:
99+
def _merge_environment(app: Entity | None, app_manifest: dict) -> dict:
100100
environment = dict()
101101
if app is not None and "environment_json" in app["entity"]:
102102
environment.update(app["entity"]["environment_json"])

cloudfoundry_client/v2/apps.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import os
44
from http import HTTPStatus
55
from time import sleep
6-
from typing import Optional, Dict, TYPE_CHECKING
6+
from typing import Dict, TYPE_CHECKING
77

88
from cloudfoundry_client.doppler.client import EnvelopeStream
99
from cloudfoundry_client.errors import InvalidStatusCode
@@ -107,9 +107,9 @@ def list_service_bindings(self, application_guid: str, **kwargs) -> Pagination[E
107107
def start(
108108
self,
109109
application_guid: str,
110-
check_time: Optional[float] = 0.5,
111-
timeout: Optional[float] = 300.0,
112-
asynchronous: Optional[bool] = False,
110+
check_time: float | None = 0.5,
111+
timeout: float | None = 300.0,
112+
asynchronous: bool | None = False,
113113
) -> Application:
114114
result = super(AppManager, self)._update(application_guid, dict(state="STARTED"))
115115
if asynchronous:
@@ -122,9 +122,9 @@ def start(
122122
def stop(
123123
self,
124124
application_guid: str,
125-
check_time: Optional[float] = 0.5,
126-
timeout: Optional[float] = 500.0,
127-
asynchronous: Optional[bool] = False,
125+
check_time: float | None = 0.5,
126+
timeout: float | None = 500.0,
127+
asynchronous: bool | None = False,
128128
) -> Application:
129129
result = super(AppManager, self)._update(application_guid, dict(state="STOPPED"))
130130
if asynchronous:
@@ -152,7 +152,7 @@ def update(self, application_guid: str, **kwargs) -> Application:
152152
def remove(self, application_guid: str):
153153
super(AppManager, self)._remove(application_guid)
154154

155-
def upload(self, application_guid: str, resources, application: str, asynchronous: Optional[bool] = False):
155+
def upload(self, application_guid: str, resources, application: str, asynchronous: bool | None = False):
156156
application_size = os.path.getsize(application)
157157
with open(application, "rb") as binary_file:
158158
return self.client.put(

cloudfoundry_client/v2/entities.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from functools import partial, reduce
2-
from typing import Callable, List, Tuple, Any, Optional, TYPE_CHECKING
2+
from typing import Callable, List, Tuple, Any, TYPE_CHECKING
33
from urllib.parse import quote
44
from requests import Response
55

@@ -50,7 +50,7 @@ class EntityManager(object):
5050
timestamp_parameters = ["timestamp"]
5151

5252
def __init__(
53-
self, target_endpoint: str, client: "CloudFoundryClient", entity_uri: str, entity_builder: Optional[EntityBuilder] = None
53+
self, target_endpoint: str, client: "CloudFoundryClient", entity_uri: str, entity_builder: EntityBuilder | None = None
5454
):
5555
self.target_endpoint = target_endpoint
5656
self.entity_uri = entity_uri
@@ -59,7 +59,7 @@ def __init__(
5959
entity_builder if entity_builder is not None else lambda pairs: Entity(target_endpoint, client, pairs)
6060
)
6161

62-
def _list(self, requested_path: str, entity_builder: Optional[EntityBuilder] = None, **kwargs) -> Pagination[Entity]:
62+
def _list(self, requested_path: str, entity_builder: EntityBuilder | None = None, **kwargs) -> Pagination[Entity]:
6363
url_requested = self._get_url_filtered("%s%s" % (self.target_endpoint, requested_path), **kwargs)
6464
current_builder = self._get_entity_builder(entity_builder)
6565
response_json = self._read_response(self.client.get(url_requested), JsonObject)
@@ -68,7 +68,7 @@ def _list(self, requested_path: str, entity_builder: Optional[EntityBuilder] = N
6868
lambda page: page["resources"],
6969
lambda json_object: current_builder(list(json_object.items())))
7070

71-
def _next_page(self, current_page: JsonObject) -> Optional[JsonObject]:
71+
def _next_page(self, current_page: JsonObject) -> JsonObject | None:
7272
next_url = current_page.get("next_url")
7373
if next_url is None:
7474
return None
@@ -87,16 +87,16 @@ def _remove(self, resource_id: str, **kwargs):
8787
url = "%s%s/%s" % (self.target_endpoint, self.entity_uri, resource_id)
8888
self._delete(url, **kwargs)
8989

90-
def _get(self, requested_path: str, entity_builder: Optional[EntityBuilder] = None) -> Entity:
90+
def _get(self, requested_path: str, entity_builder: EntityBuilder | None = None) -> Entity:
9191
url = "%s%s" % (self.target_endpoint, requested_path)
9292
response = self.client.get(url)
9393
return self._read_response(response, entity_builder)
9494

95-
def _post(self, url: str, data: Optional[dict] = None, **kwargs):
95+
def _post(self, url: str, data: dict | None = None, **kwargs):
9696
response = self.client.post(url, json=data, **kwargs)
9797
return self._read_response(response)
9898

99-
def _put(self, url: str, data: Optional[dict] = None, **kwargs):
99+
def _put(self, url: str, data: dict | None = None, **kwargs):
100100
response = self.client.put(url, json=data, **kwargs)
101101
return self._read_response(response)
102102

@@ -112,7 +112,7 @@ def __getitem__(self, entity_guid) -> Entity:
112112
def list(self, **kwargs) -> Pagination[Entity]:
113113
return self._list(self.entity_uri, **kwargs)
114114

115-
def get_first(self, **kwargs) -> Optional[Entity]:
115+
def get_first(self, **kwargs) -> Entity | None:
116116
kwargs.setdefault("results-per-page", 1)
117117
for entity in self._list(self.entity_uri, **kwargs):
118118
return entity
@@ -125,7 +125,7 @@ def get(self, entity_id: str, *extra_paths) -> Entity:
125125
requested_path = "%s/%s/%s" % (self.entity_uri, entity_id, "/".join(extra_paths))
126126
return self._get(requested_path)
127127

128-
def _read_response(self, response: Response, other_entity_builder: Optional[EntityBuilder] = None):
128+
def _read_response(self, response: Response, other_entity_builder: EntityBuilder | None = None):
129129
entity_builder = self._get_entity_builder(other_entity_builder)
130130
result = response.json(object_pairs_hook=JsonObject)
131131
return entity_builder(list(result.items()))
@@ -134,7 +134,7 @@ def _read_response(self, response: Response, other_entity_builder: Optional[Enti
134134
def _request(**mandatory_parameters) -> Request:
135135
return Request(**mandatory_parameters)
136136

137-
def _get_entity_builder(self, entity_builder: Optional[EntityBuilder]) -> EntityBuilder:
137+
def _get_entity_builder(self, entity_builder: EntityBuilder | None) -> EntityBuilder:
138138
if entity_builder is None:
139139
return self.entity_builder
140140
else:

cloudfoundry_client/v2/routes.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Optional, TYPE_CHECKING
1+
from typing import TYPE_CHECKING
22

33
from cloudfoundry_client.v2.entities import EntityManager, Entity
44

@@ -10,14 +10,14 @@ class RouteManager(EntityManager):
1010
def __init__(self, target_endpoint: str, client: "CloudFoundryClient"):
1111
super(RouteManager, self).__init__(target_endpoint, client, "/v2/routes")
1212

13-
def create_tcp_route(self, domain_guid: str, space_guid: str, port: Optional[int] = None) -> Entity:
13+
def create_tcp_route(self, domain_guid: str, space_guid: str, port: int | None = None) -> Entity:
1414
request = self._request(domain_guid=domain_guid, space_guid=space_guid)
1515
if port is None:
1616
return super(RouteManager, self)._create(request, params=dict(generate_port=True))
1717
else:
1818
request["port"] = port
1919
return super(RouteManager, self)._create(request)
2020

21-
def create_host_route(self, domain_guid: str, space_guid: str, host: str, path: Optional[str] = "") -> Entity:
21+
def create_host_route(self, domain_guid: str, space_guid: str, host: str, path: str | None = "") -> Entity:
2222
request = dict(domain_guid=domain_guid, space_guid=space_guid, host=host, path=path)
2323
return super(RouteManager, self)._create(request)

0 commit comments

Comments
 (0)