Skip to content

Commit 795eb01

Browse files
authored
🔀 Merge pull request #79 from davep/tighten-linting
2 parents 9e0d49e + 0e29ff5 commit 795eb01

File tree

10 files changed

+53
-20
lines changed

10 files changed

+53
-20
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ publish := uv publish --username=__token__ --keyring-provider=subprocess
99
test := $(run) pytest
1010
python := $(run) python
1111
ruff := $(run) ruff
12-
lint := $(ruff) check --select I
12+
lint := $(ruff) check
1313
fmt := $(ruff) format
1414
mypy := $(run) mypy
1515
mkdocs := $(run) mkdocs

pyproject.toml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,26 @@ explicit = true
8989
venvPath="."
9090
venv=".venv"
9191
exclude=[".venv"]
92+
93+
[tool.ruff.lint]
94+
select = [
95+
# pycodestyle
96+
"E",
97+
# Pyflakes
98+
"F",
99+
# pyupgrade
100+
"UP",
101+
# flake8-bugbear
102+
"B",
103+
# flake8-simplify
104+
"SIM",
105+
# isort
106+
"I",
107+
]
108+
ignore = [
109+
# I think try...expect...pass reads far better.
110+
"SIM105",
111+
]
112+
113+
[tool.ruff.lint.pycodestyle]
114+
max-line-length = 120

src/peplum/app/data/config.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
##############################################################################
44
# Python imports.
5+
from collections.abc import Iterator
56
from contextlib import contextmanager
67
from dataclasses import asdict, dataclass, field
7-
from functools import lru_cache
8+
from functools import cache
89
from json import dumps, loads
910
from pathlib import Path
10-
from typing import Iterator
1111

1212
##############################################################################
1313
# Local imports.
@@ -76,7 +76,7 @@ def save_configuration(configuration: Configuration) -> Configuration:
7676

7777

7878
##############################################################################
79-
@lru_cache(maxsize=None)
79+
@cache
8080
def load_configuration() -> Configuration:
8181
"""Load the configuration.
8282

src/peplum/app/data/peps.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77
##############################################################################
88
# Python imports.
99
from collections import Counter
10+
from collections.abc import Iterable, Iterator
1011
from dataclasses import dataclass
1112
from functools import total_ordering
1213
from itertools import chain
1314
from operator import attrgetter
1415
from pathlib import Path
15-
from typing import Iterable, Iterator, Literal, TypeAlias
16+
from typing import Literal, TypeAlias
1617

1718
##############################################################################
1819
# Packaging imports.

src/peplum/app/providers/python_versions.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,15 @@ def commands(self) -> CommandHits:
4545
"Also isn't related to a specific Python version"
4646
if self.active_peps.is_filtered
4747
else "Isn't related to a specific Python version",
48-
f"{help_prefix} to PEPs unrelated to any specific Python version (narrows down to {version.count})",
48+
f"{help_prefix} to PEPs unrelated to any specific Python version "
49+
f"(narrows down to {version.count})",
4950
ShowPythonVersion(""),
5051
)
5152
else:
5253
yield CommandHit(
5354
f"{command_prefix} {version.version}",
54-
f"{help_prefix} to PEPs related to Python version {version.version} (narrows down to {version.count})",
55+
f"{help_prefix} to PEPs related to Python version {version.version} "
56+
f"(narrows down to {version.count})",
5557
ShowPythonVersion(version.version),
5658
)
5759

src/peplum/app/screens/main.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ def load_pep_data(self) -> None:
233233
)
234234
)
235235
)
236-
except IOError as error:
236+
except OSError as error:
237237
self.notify(str(error), title="Error loading PEP data", severity="error")
238238

239239
@work(thread=True)
@@ -248,7 +248,7 @@ async def download_pep_data(self) -> None:
248248
# Store the raw data.
249249
try:
250250
pep_data().write_text(dumps(raw_data, indent=4), encoding="utf-8")
251-
except IOError as error:
251+
except OSError as error:
252252
self.notify(str(error), title="Error saving PEP data", severity="error")
253253
return
254254
# Now kick off loading the raw data.
@@ -529,7 +529,7 @@ def _save_notes(self) -> None:
529529
"""Save the notes."""
530530
try:
531531
self.notes.save()
532-
except IOError as error:
532+
except OSError as error:
533533
self.notify(
534534
str(error), title="Unable to save notes", severity="error", timeout=8
535535
)

src/peplum/app/screens/pep_viewer.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ async def _download_text(self) -> None:
116116
if self._cache_name.exists():
117117
try:
118118
pep_source = self._cache_name.read_text(encoding="utf-8")
119-
except IOError:
119+
except OSError:
120120
pass
121121

122122
if not pep_source:
@@ -125,7 +125,7 @@ async def _download_text(self) -> None:
125125
pep_source := await API().get_pep(self._pep.number),
126126
encoding="utf-8",
127127
)
128-
except IOError:
128+
except OSError:
129129
pass
130130
except API.RequestError as error:
131131
pep_source = "Error downloading PEP source"
@@ -151,7 +151,7 @@ def action_refresh(self) -> None:
151151
"""Refresh the PEP source."""
152152
try:
153153
self._cache_name.unlink(missing_ok=True)
154-
except IOError:
154+
except OSError:
155155
pass
156156
self._download_text()
157157

@@ -178,7 +178,7 @@ async def action_save(self) -> None:
178178
return
179179
try:
180180
target.write_text(self.query_one(TextArea).text, encoding="utf-8")
181-
except IOError as error:
181+
except OSError as error:
182182
self.notify(str(error), title="Save Failed", severity="error")
183183
return
184184
self.notify(str(target), title="Saved")

src/peplum/app/widgets/navigation.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
##############################################################################
88
# Python imports.
9-
from typing import Callable
9+
from collections.abc import Callable
1010

1111
##############################################################################
1212
# Rich imports.
@@ -100,7 +100,7 @@ def __init__(self, peps: PEPs, key: str, key_colour: str | None) -> None:
100100
"""
101101
super().__init__(
102102
self.count_prompt(f"All [{(key_colour or 'dim')}]\\[{key}][/]", len(peps)),
103-
id=f"_all_peps",
103+
id="_all_peps",
104104
)
105105

106106
@property
@@ -168,7 +168,7 @@ def __init__(self, version: PythonVersionCount) -> None:
168168
self._version = version
169169
"""The Python version to show."""
170170
super().__init__(
171-
self.count_prompt(version.version or f"[dim i]None[/]", version.count),
171+
self.count_prompt(version.version or "[dim i]None[/]", version.count),
172172
id=f"_python_version_{version.version}",
173173
)
174174

src/peplum/app/widgets/pep_details.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66

77
##############################################################################
88
# Python imports.
9+
from collections.abc import Sequence
910
from datetime import date, datetime
1011
from functools import singledispatchmethod
11-
from typing import Final, Sequence
12+
from typing import Final
1213
from webbrowser import open as visit_url
1314

1415
##############################################################################

tests/unit/test_peps.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@
7979
"topic": "",
8080
"created": "30-Mar-2014",
8181
"python_version": "3.13",
82-
"post_history": "30-Mar-2014, 15-Aug-2014, 16-Aug-2014, 07-Jun-2016, 01-Sep-2016, 13-Apr-2021, 03-Nov-2021, 27-Dec-2023",
82+
"post_history": (
83+
"30-Mar-2014, 15-Aug-2014, 16-Aug-2014, 07-Jun-2016, 01-Sep-2016, 13-Apr-2021, 03-Nov-2021, 27-Dec-2023"
84+
),
8385
"resolution": None,
8486
"requires": None,
8587
"replaces": None,
@@ -99,7 +101,11 @@
99101
"topic": "packaging",
100102
"created": "15-Aug-2019",
101103
"python_version": None,
102-
"post_history": "`15-Aug-2019 <https://discuss.python.org/t/2154>`__, `17-Dec-2021 <https://discuss.python.org/t/12622>`__, `10-May-2024 <https://discuss.python.org/t/53020>`__,",
104+
"post_history": (
105+
"`15-Aug-2019 <https://discuss.python.org/t/2154>`__, "
106+
"`17-Dec-2021 <https://discuss.python.org/t/12622>`__, "
107+
"`10-May-2024 <https://discuss.python.org/t/53020>`__,"
108+
),
103109
"resolution": "https://discuss.python.org/t/53020/106",
104110
"requires": None,
105111
"replaces": None,

0 commit comments

Comments
 (0)