Skip to content

Commit 274d4c9

Browse files
authored
Python 3.9 Modernization (#550)
Python 3.8 was dropped in #548.
2 parents 3a38e15 + b20e79a commit 274d4c9

25 files changed

+210
-203
lines changed

CHANGES

+10
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@ $ pip install --user --upgrade --pre libtmux
1515

1616
<!-- To maintainers and contributors: Please add notes for the forthcoming version above -->
1717

18+
### Development
19+
20+
- Aggressive automated lint fixes via `ruff` (#550)
21+
22+
via ruff v0.8.4, all automated lint fixes, including unsafe and previews were applied for Python 3.9:
23+
24+
```sh
25+
ruff check --select ALL . --fix --unsafe-fixes --preview --show-fixes; ruff format .
26+
```
27+
1828
## libtmux 0.39.0 (2024-11-26)
1929

2030
_Maintenance only, no bug fixes or new features_

conftest.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
@pytest.fixture(autouse=True)
2828
def add_doctest_fixtures(
2929
request: pytest.FixtureRequest,
30-
doctest_namespace: t.Dict[str, t.Any],
30+
doctest_namespace: dict[str, t.Any],
3131
) -> None:
3232
"""Configure doctest fixtures for pytest-doctest."""
3333
if isinstance(request._pyfuncitem, DoctestItem) and shutil.which("tmux"):

docs/conf.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
sys.path.insert(0, str(cwd / "_ext"))
2323

2424
# package data
25-
about: t.Dict[str, str] = {}
25+
about: dict[str, str] = {}
2626
with (project_src / "libtmux" / "__about__.py").open() as fp:
2727
exec(fp.read(), about)
2828

@@ -71,8 +71,8 @@
7171
html_css_files = ["css/custom.css"]
7272
html_extra_path = ["manifest.json"]
7373
html_theme = "furo"
74-
html_theme_path: t.List[str] = []
75-
html_theme_options: t.Dict[str, t.Union[str, t.List[t.Dict[str, str]]]] = {
74+
html_theme_path: list[str] = []
75+
html_theme_options: dict[str, t.Union[str, list[dict[str, str]]]] = {
7676
"light_logo": "img/libtmux.svg",
7777
"dark_logo": "img/libtmux.svg",
7878
"footer_icons": [
@@ -138,7 +138,7 @@
138138
}
139139

140140

141-
def linkcode_resolve(domain: str, info: t.Dict[str, str]) -> t.Union[None, str]:
141+
def linkcode_resolve(domain: str, info: dict[str, str]) -> t.Union[None, str]:
142142
"""
143143
Determine the URL corresponding to Python object.
144144

pyproject.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ build-backend = "hatchling.build"
119119

120120
[tool.mypy]
121121
strict = true
122+
python_version = "3.9"
122123
files = [
123124
"src",
124125
"tests",
@@ -147,7 +148,7 @@ exclude_lines = [
147148
]
148149

149150
[tool.ruff]
150-
target-version = "py38"
151+
target-version = "py39"
151152

152153
[tool.ruff.lint]
153154
select = [

src/libtmux/_internal/query_list.py

+34-34
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ class LookupProtocol(t.Protocol):
2020

2121
def __call__(
2222
self,
23-
data: t.Union[str, t.List[str], "Mapping[str, str]"],
24-
rhs: t.Union[str, t.List[str], "Mapping[str, str]", "re.Pattern[str]"],
23+
data: t.Union[str, list[str], "Mapping[str, str]"],
24+
rhs: t.Union[str, list[str], "Mapping[str, str]", "re.Pattern[str]"],
2525
) -> bool:
2626
"""Return callback for :class:`QueryList` filtering operators."""
2727
...
@@ -43,7 +43,7 @@ class ObjectDoesNotExist(Exception):
4343
def keygetter(
4444
obj: "Mapping[str, t.Any]",
4545
path: str,
46-
) -> t.Union[None, t.Any, str, t.List[str], "Mapping[str, str]"]:
46+
) -> t.Union[None, t.Any, str, list[str], "Mapping[str, str]"]:
4747
"""Fetch values in objects and keys, supported nested data.
4848
4949
**With dictionaries**:
@@ -151,15 +151,15 @@ def parse_lookup(
151151

152152

153153
def lookup_exact(
154-
data: t.Union[str, t.List[str], "Mapping[str, str]"],
155-
rhs: t.Union[str, t.List[str], "Mapping[str, str]", "re.Pattern[str]"],
154+
data: t.Union[str, list[str], "Mapping[str, str]"],
155+
rhs: t.Union[str, list[str], "Mapping[str, str]", "re.Pattern[str]"],
156156
) -> bool:
157157
return rhs == data
158158

159159

160160
def lookup_iexact(
161-
data: t.Union[str, t.List[str], "Mapping[str, str]"],
162-
rhs: t.Union[str, t.List[str], "Mapping[str, str]", "re.Pattern[str]"],
161+
data: t.Union[str, list[str], "Mapping[str, str]"],
162+
rhs: t.Union[str, list[str], "Mapping[str, str]", "re.Pattern[str]"],
163163
) -> bool:
164164
if not isinstance(rhs, str) or not isinstance(data, str):
165165
return False
@@ -168,8 +168,8 @@ def lookup_iexact(
168168

169169

170170
def lookup_contains(
171-
data: t.Union[str, t.List[str], "Mapping[str, str]"],
172-
rhs: t.Union[str, t.List[str], "Mapping[str, str]", "re.Pattern[str]"],
171+
data: t.Union[str, list[str], "Mapping[str, str]"],
172+
rhs: t.Union[str, list[str], "Mapping[str, str]", "re.Pattern[str]"],
173173
) -> bool:
174174
if not isinstance(rhs, str) or not isinstance(data, (str, Mapping, list)):
175175
return False
@@ -178,8 +178,8 @@ def lookup_contains(
178178

179179

180180
def lookup_icontains(
181-
data: t.Union[str, t.List[str], "Mapping[str, str]"],
182-
rhs: t.Union[str, t.List[str], "Mapping[str, str]", "re.Pattern[str]"],
181+
data: t.Union[str, list[str], "Mapping[str, str]"],
182+
rhs: t.Union[str, list[str], "Mapping[str, str]", "re.Pattern[str]"],
183183
) -> bool:
184184
if not isinstance(rhs, str) or not isinstance(data, (str, Mapping, list)):
185185
return False
@@ -193,8 +193,8 @@ def lookup_icontains(
193193

194194

195195
def lookup_startswith(
196-
data: t.Union[str, t.List[str], "Mapping[str, str]"],
197-
rhs: t.Union[str, t.List[str], "Mapping[str, str]", "re.Pattern[str]"],
196+
data: t.Union[str, list[str], "Mapping[str, str]"],
197+
rhs: t.Union[str, list[str], "Mapping[str, str]", "re.Pattern[str]"],
198198
) -> bool:
199199
if not isinstance(rhs, str) or not isinstance(data, str):
200200
return False
@@ -203,8 +203,8 @@ def lookup_startswith(
203203

204204

205205
def lookup_istartswith(
206-
data: t.Union[str, t.List[str], "Mapping[str, str]"],
207-
rhs: t.Union[str, t.List[str], "Mapping[str, str]", "re.Pattern[str]"],
206+
data: t.Union[str, list[str], "Mapping[str, str]"],
207+
rhs: t.Union[str, list[str], "Mapping[str, str]", "re.Pattern[str]"],
208208
) -> bool:
209209
if not isinstance(rhs, str) or not isinstance(data, str):
210210
return False
@@ -213,8 +213,8 @@ def lookup_istartswith(
213213

214214

215215
def lookup_endswith(
216-
data: t.Union[str, t.List[str], "Mapping[str, str]"],
217-
rhs: t.Union[str, t.List[str], "Mapping[str, str]", "re.Pattern[str]"],
216+
data: t.Union[str, list[str], "Mapping[str, str]"],
217+
rhs: t.Union[str, list[str], "Mapping[str, str]", "re.Pattern[str]"],
218218
) -> bool:
219219
if not isinstance(rhs, str) or not isinstance(data, str):
220220
return False
@@ -223,17 +223,17 @@ def lookup_endswith(
223223

224224

225225
def lookup_iendswith(
226-
data: t.Union[str, t.List[str], "Mapping[str, str]"],
227-
rhs: t.Union[str, t.List[str], "Mapping[str, str]", "re.Pattern[str]"],
226+
data: t.Union[str, list[str], "Mapping[str, str]"],
227+
rhs: t.Union[str, list[str], "Mapping[str, str]", "re.Pattern[str]"],
228228
) -> bool:
229229
if not isinstance(rhs, str) or not isinstance(data, str):
230230
return False
231231
return data.lower().endswith(rhs.lower())
232232

233233

234234
def lookup_in(
235-
data: t.Union[str, t.List[str], "Mapping[str, str]"],
236-
rhs: t.Union[str, t.List[str], "Mapping[str, str]", "re.Pattern[str]"],
235+
data: t.Union[str, list[str], "Mapping[str, str]"],
236+
rhs: t.Union[str, list[str], "Mapping[str, str]", "re.Pattern[str]"],
237237
) -> bool:
238238
if isinstance(rhs, list):
239239
return data in rhs
@@ -254,8 +254,8 @@ def lookup_in(
254254

255255

256256
def lookup_nin(
257-
data: t.Union[str, t.List[str], "Mapping[str, str]"],
258-
rhs: t.Union[str, t.List[str], "Mapping[str, str]", "re.Pattern[str]"],
257+
data: t.Union[str, list[str], "Mapping[str, str]"],
258+
rhs: t.Union[str, list[str], "Mapping[str, str]", "re.Pattern[str]"],
259259
) -> bool:
260260
if isinstance(rhs, list):
261261
return data not in rhs
@@ -276,17 +276,17 @@ def lookup_nin(
276276

277277

278278
def lookup_regex(
279-
data: t.Union[str, t.List[str], "Mapping[str, str]"],
280-
rhs: t.Union[str, t.List[str], "Mapping[str, str]", "re.Pattern[str]"],
279+
data: t.Union[str, list[str], "Mapping[str, str]"],
280+
rhs: t.Union[str, list[str], "Mapping[str, str]", "re.Pattern[str]"],
281281
) -> bool:
282282
if isinstance(data, (str, bytes, re.Pattern)) and isinstance(rhs, (str, bytes)):
283283
return bool(re.search(rhs, data))
284284
return False
285285

286286

287287
def lookup_iregex(
288-
data: t.Union[str, t.List[str], "Mapping[str, str]"],
289-
rhs: t.Union[str, t.List[str], "Mapping[str, str]", "re.Pattern[str]"],
288+
data: t.Union[str, list[str], "Mapping[str, str]"],
289+
rhs: t.Union[str, list[str], "Mapping[str, str]", "re.Pattern[str]"],
290290
) -> bool:
291291
if isinstance(data, (str, bytes, re.Pattern)) and isinstance(rhs, (str, bytes)):
292292
return bool(re.search(rhs, data, re.IGNORECASE))
@@ -320,7 +320,7 @@ def __init__(self, op: str, *args: object) -> None:
320320
return super().__init__(f"{op} not in LOOKUP_NAME_MAP")
321321

322322

323-
class QueryList(t.List[T], t.Generic[T]):
323+
class QueryList(list[T], t.Generic[T]):
324324
"""Filter list of object/dictionaries. For small, local datasets.
325325
326326
*Experimental, unstable*.
@@ -475,7 +475,7 @@ class QueryList(t.List[T], t.Generic[T]):
475475
def __init__(self, items: t.Optional["Iterable[T]"] = None) -> None:
476476
super().__init__(items if items is not None else [])
477477

478-
def items(self) -> t.List[t.Tuple[str, T]]:
478+
def items(self) -> list[tuple[str, T]]:
479479
if self.pk_key is None:
480480
raise PKRequiredException
481481
return [(getattr(item, self.pk_key), item) for item in self]
@@ -531,19 +531,19 @@ def filter_lookup(obj: t.Any) -> bool:
531531
return True
532532

533533
if callable(matcher):
534-
_filter = matcher
534+
filter_ = matcher
535535
elif matcher is not None:
536536

537-
def val_match(obj: t.Union[str, t.List[t.Any], T]) -> bool:
537+
def val_match(obj: t.Union[str, list[t.Any], T]) -> bool:
538538
if isinstance(matcher, list):
539539
return obj in matcher
540540
return bool(obj == matcher)
541541

542-
_filter = val_match
542+
filter_ = val_match
543543
else:
544-
_filter = filter_lookup
544+
filter_ = filter_lookup
545545

546-
return self.__class__(k for k in self if _filter(k))
546+
return self.__class__(k for k in self if filter_(k))
547547

548548
def get(
549549
self,

0 commit comments

Comments
 (0)