Skip to content

Commit f238c2e

Browse files
authored
test: add pylint linter (#248)
* chore: add pylint linter * refactor: fix linting errors * docs: fix incomplete docstring
1 parent 4374a7b commit f238c2e

21 files changed

Lines changed: 96 additions & 24 deletions

File tree

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ venv:
66
venv/bin/pip install -e .[docs,test]
77

88
lint: venv
9+
venv/bin/pylint hcloud
910
venv/bin/mypy hcloud
1011

1112
test: venv

hcloud/_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def __init__(
4242
poll_interval: int = 1,
4343
timeout: float | tuple[float, float] | None = None,
4444
):
45-
"""Create an new Client instance
45+
"""Create a new Client instance
4646
4747
:param token: Hetzner Cloud API token
4848
:param api_endpoint: Hetzner Cloud API endpoint

hcloud/actions/client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def wait_until_finished(self, max_retries: int = 100) -> None:
2727
while self.status == Action.STATUS_RUNNING:
2828
if max_retries > 0:
2929
self.reload()
30+
# pylint: disable=protected-access
3031
time.sleep(self._client._client.poll_interval)
3132
max_retries = max_retries - 1
3233
else:

hcloud/core/client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ def _iter_pages( # type: ignore[no-untyped-def]
4545

4646
def _get_first_by(self, **kwargs): # type: ignore[no-untyped-def]
4747
assert hasattr(self, "get_list")
48+
# pylint: disable=no-member
4849
entities, _ = self.get_list(**kwargs)
4950
return entities[0] if entities else None
5051

hcloud/core/domain.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ class BaseDomain:
66

77
@classmethod
88
def from_dict(cls, data: dict): # type: ignore[no-untyped-def]
9+
"""
10+
Build the domain object from the data dict.
11+
"""
912
supported_data = {k: v for k, v in data.items() if k in cls.__slots__}
1013
return cls(**supported_data)
1114

@@ -22,12 +25,14 @@ class DomainIdentityMixin:
2225

2326
@property
2427
def id_or_name(self) -> int | str:
28+
"""
29+
Return the first defined value, and fails if none is defined.
30+
"""
2531
if self.id is not None:
2632
return self.id
27-
elif self.name is not None:
33+
if self.name is not None:
2834
return self.name
29-
else:
30-
raise ValueError("id or name must be set")
35+
raise ValueError("id or name must be set")
3136

3237

3338
class Pagination(BaseDomain):
@@ -65,6 +70,9 @@ def __init__(self, pagination: Pagination | None = None):
6570

6671
@classmethod
6772
def parse_meta(cls, response: dict) -> Meta | None:
73+
"""
74+
If present, extract the meta details from the response and return a meta object.
75+
"""
6876
meta = None
6977
if response and "meta" in response:
7078
meta = cls()

hcloud/firewalls/client.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,29 +39,32 @@ def __init__(self, client: FirewallsClient, data: dict, complete: bool = True):
3939

4040
applied_to = data.get("applied_to", [])
4141
if applied_to:
42+
# pylint: disable=import-outside-toplevel
4243
from ..servers import BoundServer
4344

44-
ats = []
45-
for a in applied_to:
46-
if a["type"] == FirewallResource.TYPE_SERVER:
47-
ats.append(
45+
data_applied_to = []
46+
for firewall_resource in applied_to:
47+
if firewall_resource["type"] == FirewallResource.TYPE_SERVER:
48+
data_applied_to.append(
4849
FirewallResource(
49-
type=a["type"],
50+
type=firewall_resource["type"],
5051
server=BoundServer(
51-
client._client.servers, a["server"], complete=False
52+
client._client.servers,
53+
firewall_resource["server"],
54+
complete=False,
5255
),
5356
)
5457
)
55-
elif a["type"] == FirewallResource.TYPE_LABEL_SELECTOR:
56-
ats.append(
58+
elif firewall_resource["type"] == FirewallResource.TYPE_LABEL_SELECTOR:
59+
data_applied_to.append(
5760
FirewallResource(
58-
type=a["type"],
61+
type=firewall_resource["type"],
5962
label_selector=FirewallResourceLabelSelector(
60-
selector=a["label_selector"]["selector"]
63+
selector=firewall_resource["label_selector"]["selector"]
6164
),
6265
)
6366
)
64-
data["applied_to"] = ats
67+
data["applied_to"] = data_applied_to
6568

6669
super().__init__(client, data, complete)
6770

hcloud/firewalls/domain.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ def __init__(
108108
self.description = description
109109

110110
def to_payload(self) -> dict[str, Any]:
111+
"""
112+
Generates the request payload from this domain object.
113+
"""
111114
payload: dict[str, Any] = {
112115
"direction": self.direction,
113116
"protocol": self.protocol,
@@ -151,6 +154,9 @@ def __init__(
151154
self.label_selector = label_selector
152155

153156
def to_payload(self) -> dict[str, Any]:
157+
"""
158+
Generates the request payload from this domain object.
159+
"""
154160
payload: dict[str, Any] = {"type": self.type}
155161
if self.server is not None:
156162
payload["server"] = {"id": self.server.id}

hcloud/floating_ips/client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class BoundFloatingIP(BoundModelBase):
1919
model = FloatingIP
2020

2121
def __init__(self, client: FloatingIPsClient, data: dict, complete: bool = True):
22+
# pylint: disable=import-outside-toplevel
2223
from ..servers import BoundServer
2324

2425
server = data.get("server")

hcloud/hcloud.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@
88
stacklevel=2,
99
)
1010

11+
# pylint: disable=wildcard-import,wrong-import-position,unused-wildcard-import
1112
from ._client import * # noqa

hcloud/helpers/labels.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ def validate(labels: dict[str, str]) -> bool:
1818
1919
:return: bool
2020
"""
21-
for k, v in labels.items():
22-
if LabelValidator.KEY_REGEX.match(k) is None:
21+
for key, value in labels.items():
22+
if LabelValidator.KEY_REGEX.match(key) is None:
2323
return False
24-
if LabelValidator.VALUE_REGEX.match(v) is None:
24+
if LabelValidator.VALUE_REGEX.match(value) is None:
2525
return False
2626
return True
2727

@@ -32,9 +32,15 @@ def validate_verbose(labels: dict[str, str]) -> tuple[bool, str]:
3232
3333
:return: bool, str
3434
"""
35-
for k, v in labels.items():
36-
if LabelValidator.KEY_REGEX.match(k) is None:
37-
return False, f"label key {k} is not correctly formatted"
38-
if LabelValidator.VALUE_REGEX.match(v) is None:
39-
return False, f"label value {v} (key: {k}) is not correctly formatted"
35+
for key, value in labels.items():
36+
if LabelValidator.KEY_REGEX.match(key) is None:
37+
return (
38+
False,
39+
f"label key {key} is not correctly formatted",
40+
)
41+
if LabelValidator.VALUE_REGEX.match(value) is None:
42+
return (
43+
False,
44+
f"label value {value} (key: {key}) is not correctly formatted",
45+
)
4046
return True, ""

0 commit comments

Comments
 (0)