Skip to content

Commit c311e22

Browse files
author
Lukas Pühringer
authored
Merge pull request #2597 from jku/lint-fixes
Enable linters
2 parents dbaf325 + 80882db commit c311e22

22 files changed

Lines changed: 43 additions & 56 deletions

examples/uploader/_localrepo.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,12 @@ def open(self, role: str) -> Metadata:
6262

6363
# if there is a metadata version fetched from remote, use that
6464
# HACK: access Updater internals
65-
if role in self.updater._trusted_set:
65+
trusted_set = self.updater._trusted_set # noqa: SLF001
66+
if role in trusted_set:
6667
# NOTE: The original signature wrapper (Metadata) was verified and
6768
# discarded upon inclusion in the trusted set. It is safe to use
6869
# a fresh wrapper. `close` will override existing signatures anyway.
69-
return Metadata(copy.deepcopy(self.updater._trusted_set[role]))
70+
return Metadata(copy.deepcopy(trusted_set[role]))
7071

7172
# otherwise we're creating metadata from scratch
7273
md = Metadata(Targets())

pyproject.toml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,25 +83,34 @@ line-length=80
8383
[tool.ruff.lint]
8484
select = [
8585
"A", # flake8-builtins
86+
"ANN", # flake8-annotations
87+
"ARG", # flake8-unused-arguments
8688
"B", # flake8-bugbear
8789
"BLE", # flake8-blind-except
8890
"C4", # flake8-comprehensions
8991
"D", # pydocstyle
9092
"DTZ", # flake8-datetimez
9193
"E", # pycodestyle
94+
"EXE", # flake8-executable
9295
"F", # pyflakes
9396
"I", # isort
9497
"ISC", # flake8-implicit-str-concat
9598
"N", # pep8-naming
9699
"PL", # pylint
100+
"PGH", # pygrep-hooks
101+
"PIE", # flake8-pie
102+
"PYI", # flake8-pyi
97103
"RET", # flake8-return
104+
"RSE", # flake8-raise
98105
"RUF", # ruff-specific rules
99106
"S", # flake8-bandit
100107
"SIM", # flake8-simplify
108+
"SLF", # flake8-self
101109
"UP", # pyupgrade
102110
"W", # pycodestyle-warning
103111
]
104112
ignore = [
113+
"ANN101", "ANN102", # nonsense, deprecated in ruff
105114
"D400", "D415", "D213", "D205", "D202", "D107", "D407", "D413", "D212", "D104", "D406", "D105", "D411", "D401", "D200", "D203",
106115
"PLR0913", "PLR2004",
107116
"ISC001", # incompatible with ruff formatter
@@ -111,8 +120,9 @@ ignore = [
111120
"tests/*" = [
112121
"D", # pydocstyle: no docstrings required for tests
113122
"E501", # line-too-long: embedded test data in "fmt: off" blocks is ok
114-
"S", # bandit: Not running bandit on tests
115123
"RUF012", # ruff: mutable-class-default
124+
"S", # bandit: Not running bandit on tests
125+
"SLF001" # private member access is ok in tests
116126
]
117127
"examples/*/*" = [
118128
"D", # pydocstyle: no docstrings required for examples
@@ -122,6 +132,9 @@ ignore = [
122132
"S603", # bandit: this flags all uses of subprocess.run as vulnerable
123133
]
124134

135+
[tool.ruff.lint.flake8-annotations]
136+
mypy-init-return = true
137+
125138
# mypy section
126139
# Read more here: https://mypy.readthedocs.io/en/stable/config_file.html#using-a-pyproject-toml-file
127140
[tool.mypy]

tests/__init__.py

100755100644
File mode changed.

tests/repository_simulator.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/usr/bin/env python
2-
31
# Copyright 2021, New York University and the TUF contributors
42
# SPDX-License-Identifier: MIT OR Apache-2.0
53

@@ -160,7 +158,7 @@ def rotate_keys(self, role: str) -> None:
160158
"""remove all keys for role, then add threshold of new keys"""
161159
self.root.roles[role].keyids.clear()
162160
self.signers[role].clear()
163-
for _ in range(0, self.root.roles[role].threshold):
161+
for _ in range(self.root.roles[role].threshold):
164162
signer = CryptoSigner.generate_ed25519()
165163
self.root.add_key(signer.public_key, role)
166164
self.add_signer(role, signer)

tests/test_api.py

100755100644
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/usr/bin/env python
2-
31
# Copyright 2020, New York University and the TUF contributors
42
# SPDX-License-Identifier: MIT OR Apache-2.0
53
"""Unit tests for api/metadata.py"""
@@ -255,7 +253,7 @@ def from_priv_key_uri(
255253
def public_key(self) -> Key:
256254
raise RuntimeError("Not a real signer")
257255

258-
def sign(self, payload: bytes) -> Signature:
256+
def sign(self, _payload: bytes) -> Signature:
259257
raise RuntimeError("signing failed")
260258

261259
failing_signer = FailingSigner()
@@ -1118,7 +1116,7 @@ def test_delegations_get_delegated_role(self) -> None:
11181116
for name in ["prefix-", "prefix--1", f"prefix-{2**bit_len:0x}"]:
11191117
with self.assertRaises(ValueError, msg=f"role name '{name}'"):
11201118
targets.get_delegated_role(name)
1121-
for i in range(0, 2**bit_len):
1119+
for i in range(2**bit_len):
11221120
self.assertEqual(
11231121
targets.get_delegated_role(f"prefix-{i:0x}"), role2
11241122
)
@@ -1175,7 +1173,7 @@ def test_fail_envelope_deserialization(self) -> None:
11751173

11761174
def test_fail_payload_serialization(self) -> None:
11771175
with self.assertRaises(SerializationError):
1178-
SimpleEnvelope.from_signed("foo") # type: ignore
1176+
SimpleEnvelope.from_signed("foo") # type: ignore[type-var]
11791177

11801178
def test_fail_payload_deserialization(self) -> None:
11811179
payloads = [b"[", b'{"_type": "foo"}']

tests/test_examples.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#!/usr/bin/env python
21
# Copyright 2020, New York University and the TUF contributors
32
# SPDX-License-Identifier: MIT OR Apache-2.0
43
"""Unit tests for 'examples' scripts."""

tests/test_fetcher_ng.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/usr/bin/env python
2-
31
# Copyright 2021, New York University and the TUF contributors
42
# SPDX-License-Identifier: MIT OR Apache-2.0
53

@@ -107,7 +105,7 @@ def test_http_error(self) -> None:
107105

108106
# Response read timeout error
109107
@patch.object(requests.Session, "get")
110-
def test_response_read_timeout(self, mock_session_get: Any) -> None:
108+
def test_response_read_timeout(self, mock_session_get: Mock) -> None:
111109
mock_response = Mock()
112110
attr = {
113111
"iter_content.side_effect": requests.exceptions.ConnectionError(
@@ -127,7 +125,7 @@ def test_response_read_timeout(self, mock_session_get: Any) -> None:
127125
"get",
128126
side_effect=requests.exceptions.Timeout("Simulated timeout"),
129127
)
130-
def test_session_get_timeout(self, mock_session_get: Any) -> None:
128+
def test_session_get_timeout(self, mock_session_get: Mock) -> None:
131129
with self.assertRaises(exceptions.SlowRetrievalError):
132130
self.fetcher.fetch(self.url)
133131
mock_session_get.assert_called_once()

tests/test_metadata_eq_.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/usr/bin/env python
2-
31
# Copyright New York University and the TUF contributors
42
# SPDX-License-Identifier: MIT OR Apache-2.0
53

@@ -132,7 +130,7 @@ def test_md_eq_special_signatures_tests(self) -> None:
132130
self.assertEqual(md, md_2)
133131

134132
# Metadata objects with different signatures types are not equal.
135-
md_2.signatures = "" # type: ignore
133+
md_2.signatures = "" # type: ignore[assignment]
136134
self.assertNotEqual(md, md_2)
137135

138136
def test_delegations_eq_roles_reversed_order(self) -> None:

tests/test_updater_consistent_snapshot.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/usr/bin/env python
2-
31
# Copyright 2021, New York University and the TUF contributors
42
# SPDX-License-Identifier: MIT OR Apache-2.0
53

tests/test_updater_delegation_graphs.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/usr/bin/env python
2-
31
# Copyright 2021, New York University and the TUF contributors
42
# SPDX-License-Identifier: MIT OR Apache-2.0
53

0 commit comments

Comments
 (0)