Skip to content

Commit 205363d

Browse files
committed
Enable pyupgrade (U) checks
1 parent d46202e commit 205363d

9 files changed

Lines changed: 55 additions & 63 deletions

File tree

docs/conf.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
#
32
# git-pw documentation build configuration file
43

git_pw/api.py

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
CONF = config.CONF
2020
LOG = logging.getLogger(__name__)
2121

22-
Filters = ty.List[ty.Tuple[str, str]]
22+
Filters = list[tuple[str, str]]
2323

2424

2525
class HTTPTokenAuth(requests.auth.AuthBase):
@@ -38,10 +38,10 @@ def __call__(
3838
@staticmethod
3939
def _token_auth_str(token: str) -> str:
4040
"""Return a Token auth string."""
41-
return 'Token {}'.format(token.strip())
41+
return f'Token {token.strip()}'
4242

4343

44-
def _get_auth(optional: bool = False) -> ty.Optional[requests.auth.AuthBase]:
44+
def _get_auth(optional: bool = False) -> requests.auth.AuthBase | None:
4545
if CONF.token:
4646
return HTTPTokenAuth(CONF.token)
4747
elif CONF.username and CONF.password:
@@ -56,9 +56,9 @@ def _get_auth(optional: bool = False) -> ty.Optional[requests.auth.AuthBase]:
5656
return None
5757

5858

59-
def _get_headers() -> ty.Dict[str, str]:
59+
def _get_headers() -> dict[str, str]:
6060
return {
61-
'User-Agent': 'git-pw ({})'.format(git_pw.__version__),
61+
'User-Agent': f'git-pw ({git_pw.__version__})',
6262
}
6363

6464

@@ -123,7 +123,7 @@ def _handle_error(
123123

124124
else:
125125
LOG.error(
126-
'Failed to %s resource. Is your configuration correct?' % operation
126+
f'Failed to {operation} resource. Is your configuration correct?'
127127
)
128128
LOG.error("Use the '--debug' flag for more information")
129129

@@ -135,7 +135,7 @@ def _handle_error(
135135

136136
def _get(
137137
url: str,
138-
params: ty.Optional[Filters] = None,
138+
params: Filters | None = None,
139139
stream: bool = False,
140140
) -> requests.Response:
141141
"""Make GET request and handle errors."""
@@ -163,7 +163,7 @@ def _get(
163163

164164
def _post(
165165
url: str,
166-
data: ty.List[ty.Tuple[str, ty.Any]],
166+
data: list[tuple[str, ty.Any]],
167167
) -> requests.Response:
168168
"""Make POST request and handle errors."""
169169
LOG.debug('POST %s, data=%r', url, data)
@@ -183,7 +183,7 @@ def _post(
183183

184184
def _patch(
185185
url: str,
186-
data: ty.List[ty.Tuple[str, ty.Any]],
186+
data: list[tuple[str, ty.Any]],
187187
) -> requests.Response:
188188
"""Make PATCH request and handle errors."""
189189
LOG.debug('PATCH %s, data=%r', url, data)
@@ -219,7 +219,7 @@ def _delete(url: str) -> requests.Response:
219219
return rsp
220220

221221

222-
def version() -> ty.Tuple[int, int]:
222+
def version() -> tuple[int, int]:
223223
"""Get the version of the server from the URL, if present."""
224224
server = _get_server()
225225

@@ -231,16 +231,16 @@ def version() -> ty.Tuple[int, int]:
231231
return (1, 0)
232232

233233

234-
def get(url: str, params: ty.Optional[Filters]) -> ty.Dict:
234+
def get(url: str, params: Filters | None) -> dict:
235235
"""Get a JSON document from the API and return it as a dict."""
236236
return _get(url, params, stream=False).json()
237237

238238

239239
def download(
240240
url: str,
241-
params: ty.Optional[Filters] = None,
242-
output: ty.Optional[ty.Optional[str]] = None,
243-
) -> ty.Optional[str]:
241+
params: Filters | None = None,
242+
output: str | None = None,
243+
) -> str | None:
244244
"""Retrieve a specific API resource and save it to a file/stdout.
245245
246246
The ``Content-Disposition`` header is assumed to be present and
@@ -295,7 +295,7 @@ def download(
295295
return output_path
296296

297297

298-
def index(resource_type: str, params: ty.Optional[Filters] = None) -> dict:
298+
def index(resource_type: str, params: Filters | None = None) -> dict:
299299
"""List API resources.
300300
301301
GET /{resource}/
@@ -323,9 +323,9 @@ def index(resource_type: str, params: ty.Optional[Filters] = None) -> dict:
323323

324324
def detail(
325325
resource_type: str,
326-
resource_id: ty.Union[str, int],
327-
params: ty.Optional[Filters] = None,
328-
) -> ty.Dict:
326+
resource_id: str | int,
327+
params: Filters | None = None,
328+
) -> dict:
329329
"""Retrieve a specific API resource.
330330
331331
GET /{resource}/{resourceID}/
@@ -346,7 +346,7 @@ def detail(
346346

347347
def create(
348348
resource_type: str,
349-
data: ty.List[ty.Tuple[str, ty.Any]],
349+
data: list[tuple[str, ty.Any]],
350350
) -> dict:
351351
"""Create a new API resource.
352352
@@ -365,7 +365,7 @@ def create(
365365
return _post(url, data).json()
366366

367367

368-
def delete(resource_type: str, resource_id: ty.Union[str, int]) -> None:
368+
def delete(resource_type: str, resource_id: str | int) -> None:
369369
"""Delete a specific API resource.
370370
371371
DELETE /{resource}/{resourceID}/
@@ -385,8 +385,8 @@ def delete(resource_type: str, resource_id: ty.Union[str, int]) -> None:
385385

386386
def update(
387387
resource_type: str,
388-
resource_id: ty.Union[str, int],
389-
data: ty.List[ty.Tuple[str, ty.Any]],
388+
resource_id: str | int,
389+
data: list[tuple[str, ty.Any]],
390390
) -> dict:
391391
"""Update a specific API resource.
392392
@@ -407,7 +407,7 @@ def update(
407407

408408

409409
def validate_minimum_version(
410-
min_version: ty.Tuple[int, int],
410+
min_version: tuple[int, int],
411411
msg: str,
412412
) -> ty.Callable[[ty.Any], ty.Any]:
413413
def inner(f):
@@ -458,7 +458,7 @@ def retrieve_filter_ids(
458458
resource_type: str,
459459
filter_name: str,
460460
filter_value: str,
461-
) -> ty.List[ty.Tuple[str, str]]:
461+
) -> list[tuple[str, str]]:
462462
"""Retrieve IDs for items passed through by filter.
463463
464464
Some filters require client-side filtering, e.g. filtering patches by

git_pw/bundle.py

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

55
import logging
66
import sys
7-
import typing as ty
87

98
import click
109

@@ -46,7 +45,7 @@ def _get_bundle(bundle_id: str) -> dict:
4645
)
4746
@click.argument('bundle_id')
4847
@click.argument('args', nargs=-1, type=click.UNPROCESSED)
49-
def apply_cmd(bundle_id: str, args: ty.Tuple[str]) -> None:
48+
def apply_cmd(bundle_id: str, args: tuple[str]) -> None:
5049
"""Apply bundle.
5150
5251
Apply a bundle locally using the 'git-am' command. Any additional ARGS
@@ -68,7 +67,7 @@ def apply_cmd(bundle_id: str, args: ty.Tuple[str]) -> None:
6867
type=click.Path(file_okay=True, writable=True, readable=True),
6968
required=False,
7069
)
71-
def download_cmd(bundle_id: str, output: ty.Optional[str]) -> None:
70+
def download_cmd(bundle_id: str, output: str | None) -> None:
7271
"""Download bundle in mbox format.
7372
7473
Download a bundle but do not apply it. ``OUTPUT`` is optional and can be an
@@ -210,7 +209,7 @@ def list_cmd(owners, limit, page, sort, fmt, headers, name):
210209
@utils.format_options
211210
def create_cmd(
212211
name: str,
213-
patch_ids: ty.Tuple[int],
212+
patch_ids: tuple[int],
214213
public: bool,
215214
fmt: str,
216215
) -> None:
@@ -264,7 +263,7 @@ def create_cmd(
264263
def update_cmd(
265264
bundle_id: str,
266265
name: str,
267-
patch_ids: ty.List[int],
266+
patch_ids: list[int],
268267
public: bool,
269268
fmt: str,
270269
) -> None:
@@ -327,7 +326,7 @@ def delete_cmd(bundle_id: str, fmt: str) -> None:
327326
'Modifying bundles is only supported from API version 1.2',
328327
)
329328
@utils.format_options
330-
def add_cmd(bundle_id: str, patch_ids: ty.Tuple[int], fmt: str) -> None:
329+
def add_cmd(bundle_id: str, patch_ids: tuple[int], fmt: str) -> None:
331330
"""Add one or more patches to a bundle.
332331
333332
Append the provided PATCH_IDS to bundle BUNDLE_ID.
@@ -357,7 +356,7 @@ def add_cmd(bundle_id: str, patch_ids: ty.Tuple[int], fmt: str) -> None:
357356
@utils.format_options
358357
def remove_cmd(
359358
bundle_id: str,
360-
patch_ids: ty.Tuple[int],
359+
patch_ids: tuple[int],
361360
fmt: str,
362361
) -> None:
363362
"""Remove one or more patches from a bundle.

git_pw/config.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"""
44

55
import logging
6-
import typing as ty
76

87
from git_pw import utils
98

@@ -21,28 +20,28 @@ def parse_boolean(value: str) -> bool:
2120
if value in ('no', 'off', 'false', '0'):
2221
return False
2322

24-
LOG.error("'{}' is not a valid boolean value".format(value))
23+
LOG.error(f"'{value}' is not a valid boolean value")
2524
return False
2625

2726

28-
class Config(object):
27+
class Config:
2928
def __init__(self) -> None:
30-
self._git_config: ty.Dict[str, str] = {}
29+
self._git_config: dict[str, str] = {}
3130

3231
def __getattribute__(self, name: str) -> str:
3332
# attempt to use any attributes first
3433
try:
35-
value = super(Config, self).__getattribute__(name)
34+
value = super().__getattribute__(name)
3635
except AttributeError:
3736
value = None
3837
if value:
39-
LOG.debug("Retrieved '{}' setting from cache".format(name))
38+
LOG.debug(f"Retrieved '{name}' setting from cache")
4039
return value
4140

4241
# fallback to reading from git config otherwise
43-
value = utils.git_config('pw.{}'.format(name))
42+
value = utils.git_config(f'pw.{name}')
4443
if value:
45-
LOG.debug("Retrieved '{}' setting from git-config".format(name))
44+
LOG.debug(f"Retrieved '{name}' setting from git-config")
4645

4746
setattr(self, name, value)
4847

git_pw/patch.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,7 @@ def _format_series(series):
161161
('URL', patch.get('web_url')),
162162
(
163163
'Submitter',
164-
'%s (%s)'
165-
% (
164+
'{} ({})'.format(
166165
patch.get('submitter').get('name'),
167166
patch.get('submitter').get('email'),
168167
),
@@ -423,8 +422,7 @@ def list_cmd(
423422
patch.get('id'),
424423
arrow.get(patch.get('date')).humanize(),
425424
utils.trim(patch.get('name')),
426-
'%s (%s)'
427-
% (
425+
'{} ({})'.format(
428426
patch.get('submitter').get('name'),
429427
patch.get('submitter').get('email'),
430428
),

git_pw/series.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,7 @@ def _format_submission(submission):
148148
('URL', series.get('web_url')),
149149
(
150150
'Submitter',
151-
'%s (%s)'
152-
% (
151+
'{} ({})'.format(
153152
series.get('submitter').get('name'),
154153
series.get('submitter').get('email'),
155154
),
@@ -248,8 +247,7 @@ def list_cmd(submitters, limit, page, sort, fmt, headers, name, since, before):
248247
arrow.get(series_.get('date')).humanize(),
249248
utils.trim(series_.get('name') or ''),
250249
series_.get('version'),
251-
'%s (%s)'
252-
% (
250+
'{} ({})'.format(
253251
series_.get('submitter').get('name'),
254252
series_.get('submitter').get('email'),
255253
),

git_pw/utils.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def git_config(value: str) -> str:
5252
return output.decode('utf-8').strip()
5353

5454

55-
def git_am(mbox: str, args: ty.Tuple[str, ...]) -> None:
55+
def git_am(mbox: str, args: tuple[str, ...]) -> None:
5656
"""Execute git-am on a given mbox file."""
5757
cmd = ['git', 'am']
5858
if args:
@@ -74,8 +74,8 @@ def git_am(mbox: str, args: ty.Tuple[str, ...]) -> None:
7474

7575

7676
def _tabulate(
77-
output: ty.List[ty.Tuple[str, ty.Any]],
78-
headers: ty.List[str],
77+
output: list[tuple[str, ty.Any]],
78+
headers: list[str],
7979
fmt: str,
8080
) -> str:
8181
fmt = fmt or git_config('pw.format') or 'table'
@@ -115,7 +115,7 @@ def _echo_via_pager(pager: str, output: str) -> None:
115115

116116
try:
117117
proc.communicate(input=output.encode('utf-8', 'strict'))
118-
except (IOError, KeyboardInterrupt):
118+
except (OSError, KeyboardInterrupt):
119119
pass
120120
else:
121121
if proc.stdin:
@@ -131,8 +131,8 @@ def _echo_via_pager(pager: str, output: str) -> None:
131131

132132

133133
def echo_via_pager(
134-
output: ty.List[ty.Tuple[str, ty.Any]],
135-
headers: ty.List[str],
134+
output: list[tuple[str, ty.Any]],
135+
headers: list[str],
136136
fmt: str,
137137
) -> None:
138138
"""Echo using git's default pager.
@@ -165,15 +165,15 @@ def echo_via_pager(
165165

166166

167167
def echo(
168-
output: ty.List[ty.Tuple[str, ty.Any]],
169-
headers: ty.List[str],
168+
output: list[tuple[str, ty.Any]],
169+
headers: list[str],
170170
fmt: str,
171171
) -> None:
172172
click.echo(_tabulate(output, headers, fmt))
173173

174174

175175
def pagination_options(
176-
sort_fields: ty.Tuple[str, ...],
176+
sort_fields: tuple[str, ...],
177177
default_sort: str,
178178
) -> ty.Callable:
179179
"""Shared pagination options."""
@@ -230,8 +230,8 @@ def _date_options(f):
230230

231231

232232
def format_options(
233-
original_function: ty.Optional[ty.Callable] = None,
234-
headers: ty.Optional[ty.Tuple[str, ...]] = None,
233+
original_function: ty.Callable | None = None,
234+
headers: tuple[str, ...] | None = None,
235235
) -> ty.Callable:
236236
"""Shared output format options."""
237237

0 commit comments

Comments
 (0)