Skip to content

Commit c0ccfbf

Browse files
committed
Use fancier output formatting
Use fanciers output formatting by using formatted string literals (also called f-strings). For more information see: https://docs.python.org/3/reference/lexical_analysis.html#f-strings Signed-off-by: Roald Nefs <info@roaldnefs.com>
1 parent 49f6869 commit c0ccfbf

4 files changed

Lines changed: 10 additions & 35 deletions

File tree

transip/__init__.py

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -49,31 +49,20 @@ def __init__(
4949
) -> None:
5050

5151
self._api_version: str = api_version
52-
self._url: str = "https://api.transip.nl/v{version}".format(
53-
version=api_version
54-
)
52+
self._url: str = f"https://api.transip.nl/v{api_version}"
5553
self._access_token: Optional[str] = access_token
5654

5755
# Headers to use when making a request to TransIP
5856
self.headers: Dict[str, str] = {
59-
"User-Agent": "{title}/{version}".format(
60-
title=__title__,
61-
version=__version__
62-
),
63-
"Authorization": "Bearer {token}".format(
64-
token=access_token
65-
)
57+
"User-Agent": f"{__title__}/{__version__}",
58+
"Authorization": f"Bearer {access_token}"
6659
}
6760

6861
# Initialize a session object for making requests
6962
self.session: requests.Session = requests.Session()
7063

7164
# Dynamically import the services for the specified API version
72-
services = importlib.import_module(
73-
"transip.v{version}.services".format(
74-
version=api_version
75-
)
76-
)
65+
services = importlib.import_module(f"transip.v{api_version}.services")
7766

7867
self.availability_zones: Type[Any] = (
7968
services.AvailabilityZoneService(self) # type: ignore
@@ -96,10 +85,7 @@ def _get_headers(
9685
return headers
9786

9887
def _build_url(self, path: str) -> str:
99-
return "{api_url}{path}".format(
100-
api_url=self._url,
101-
path=path
102-
)
88+
return f"{self._url}{path}"
10389

10490
def _send(
10591
self,

transip/base.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,14 @@ def __setattr__(self, name: str, value: Any) -> None:
4040
self.__dict__["_attrs"][name] = value
4141

4242
def __str__(self) -> str:
43-
return "{} => {}".format(type(self), self._attrs)
43+
return f"{type(self)} => {self._attrs}"
4444

4545
def __repr__(self) -> str:
4646
name = self.__class__.__name__
4747
if self._id_attr:
48-
return "<{name} {id}:{value}>".format(
49-
name=name,
50-
id=self._id_attr,
51-
value=self.get_id()
52-
)
48+
return f"<{name} {self._id_attr}:{self.get_id()}>"
5349
else:
54-
return "<{name}>".format(name=name)
50+
return f"<{name}>"
5551

5652
def __dir__(self):
5753
return super().__dir__() + list(self.attrs)

transip/exceptions.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,7 @@ def __init__(
4343

4444
def __str__(self) -> str:
4545
if self.response_code:
46-
return "{code}: {message}".format(
47-
code=self.response_code,
48-
message=self.message
49-
)
46+
return f"{self.response_code}: {self.message}"
5047
else:
5148
return self.message
5249

transip/mixins.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,8 @@ class GetMixin:
3838

3939
def get(self, id: str, **kwargs) -> Optional[Type[ApiObject]]:
4040
if self._obj_cls or self._path or self._resp_get_attr:
41-
path: str = "{path}/{id}".format(
42-
path=self._path,
43-
id=id
44-
)
4541
obj: Type[ApiObject] = self._obj_cls( # type: ignore
46-
self.client.get(path)[self._resp_get_attr]
42+
self.client.get(f"{self._path}/{id}")[self._resp_get_attr]
4743
)
4844
return obj
4945
return None

0 commit comments

Comments
 (0)