Skip to content

Commit 212e309

Browse files
committed
Apply Ruff code quality improvements
- Fixed 103 style and code quality issues automatically - Simplified boolean expressions (bool(...) instead of True if ... else False) - Updated to modern super() syntax - Removed explicit format string indices - Fixed contextlib usage patterns Ignored rules that would change behavior: - B904: Exception chaining (maintains current error handling) - N818: Exception naming (preserves established patterns) - F401: Re-export imports in __init__.py All 172 tests still passing.
1 parent acfd6e2 commit 212e309

File tree

24 files changed

+128
-149
lines changed

24 files changed

+128
-149
lines changed

docs/source/conf.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,16 @@
1515

1616
# Add any Sphinx extension module names here, as strings. They can be
1717
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
18-
extensions = [
19-
'sphinx.ext.autodoc',
20-
'sphinx.ext.viewcode',
21-
'cliff.sphinxext'
22-
]
18+
extensions = ["sphinx.ext.autodoc", "sphinx.ext.viewcode", "cliff.sphinxext"]
2319

2420
# Options for cliff.sphinxext plugin
25-
autoprogram_cliff_application = 'gerrit'
21+
autoprogram_cliff_application = "gerrit"
2622

2723
# The suffix of source filenames.
28-
source_suffix = '.rst'
24+
source_suffix = ".rst"
2925

3026
# The master toctree document.
31-
master_doc = 'index'
27+
master_doc = "index"
3228

3329
# General information about the project.
34-
project = 'python-gerritclient'
30+
project = "python-gerritclient"

gerritclient/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def __init__(self, url, auth_type=None, username=None, password=None):
6363
def is_authed(self):
6464
"""Checks whether credentials were passed."""
6565

66-
return True if self._auth else False
66+
return bool(self._auth)
6767

6868
@staticmethod
6969
def _make_common_headers():

gerritclient/commands/account.py

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class AccountList(AccountMixIn, base.BaseListCommand):
3131
columns = ("_account_id",)
3232

3333
def get_parser(self, app_name):
34-
parser = super(AccountList, self).get_parser(app_name)
34+
parser = super().get_parser(app_name)
3535
parser.add_argument("query", help="Query string.")
3636
parser.add_argument(
3737
"--suggest", action="store_true", help="Get account suggestions."
@@ -86,7 +86,7 @@ class AccountShow(AccountMixIn, base.BaseShowCommand):
8686
columns = ("_account_id", "name", "email", "username", "status")
8787

8888
def get_parser(self, prog_name):
89-
parser = super(AccountShow, self).get_parser(prog_name)
89+
parser = super().get_parser(prog_name)
9090
parser.add_argument(
9191
"-a", "--all", action="store_true", help="Show more details about account."
9292
)
@@ -119,7 +119,7 @@ def attribute(self):
119119
pass
120120

121121
def get_parser(self, prog_name):
122-
parser = super(BaseAccountSetCommand, self).get_parser(prog_name)
122+
parser = super().get_parser(prog_name)
123123
parser.add_argument(
124124
"account_id", metavar="account-identifier", help="Account identifier."
125125
)
@@ -132,9 +132,7 @@ def get_parser(self, prog_name):
132132

133133
def take_action(self, parsed_args):
134134
self.action(parsed_args.account_id, parsed_args.attribute)
135-
msg = (
136-
f"{self.attribute.capitalize()} for the account with identifier '{parsed_args.account_id}' was successfully set.\n"
137-
)
135+
msg = f"{self.attribute.capitalize()} for the account with identifier '{parsed_args.account_id}' was successfully set.\n"
138136
self.app.stdout.write(msg)
139137

140138

@@ -207,7 +205,7 @@ class AccountSetPassword(AccountMixIn, base.BaseShowCommand):
207205
columns = ("account_identifier", "http_password")
208206

209207
def get_parser(self, prog_name):
210-
parser = super(AccountSetPassword, self).get_parser(prog_name)
208+
parser = super().get_parser(prog_name)
211209
group = parser.add_mutually_exclusive_group(required=True)
212210
group.add_argument(
213211
"--generate", action="store_true", help="Generate HTTP password."
@@ -232,7 +230,7 @@ class AccountDeletePassword(AccountMixIn, base.BaseCommand):
232230
"""Deletes the HTTP password of an account in Gerrit."""
233231

234232
def get_parser(self, prog_name):
235-
parser = super(AccountDeletePassword, self).get_parser(prog_name)
233+
parser = super().get_parser(prog_name)
236234
parser.add_argument(
237235
"account_id", metavar="account-identifier", help="Account identifier."
238236
)
@@ -253,7 +251,7 @@ class AccountSSHKeyList(AccountMixIn, base.BaseListCommand):
253251
columns = ("seq", "ssh_public_key", "encoded_key", "algorithm", "comment", "valid")
254252

255253
def get_parser(self, prog_name):
256-
parser = super(AccountSSHKeyList, self).get_parser(prog_name)
254+
parser = super().get_parser(prog_name)
257255
parser.add_argument(
258256
"account_id", metavar="account-identifier", help="Account identifier."
259257
)
@@ -272,7 +270,7 @@ class AccountSSHKeyShow(AccountMixIn, base.BaseShowCommand):
272270
columns = ("seq", "ssh_public_key", "encoded_key", "algorithm", "comment", "valid")
273271

274272
def get_parser(self, app_name):
275-
parser = super(AccountSSHKeyShow, self).get_parser(app_name)
273+
parser = super().get_parser(app_name)
276274
parser.add_argument(
277275
"-s",
278276
"--sequence-id",
@@ -298,13 +296,11 @@ class AccountSSHKeyAdd(AccountMixIn, base.BaseShowCommand):
298296
@staticmethod
299297
def get_file_path(file_path):
300298
if not utils.file_exists(file_path):
301-
raise argparse.ArgumentTypeError(
302-
f"File '{file_path}' does not exist"
303-
)
299+
raise argparse.ArgumentTypeError(f"File '{file_path}' does not exist")
304300
return file_path
305301

306302
def get_parser(self, app_name):
307-
parser = super(AccountSSHKeyAdd, self).get_parser(app_name)
303+
parser = super().get_parser(app_name)
308304
group = parser.add_mutually_exclusive_group(required=True)
309305
group.add_argument("--ssh-key", help="The SSH public key.")
310306
group.add_argument(
@@ -334,7 +330,7 @@ class AccountSSHKeyDelete(AccountMixIn, base.BaseCommand):
334330
"""Deletes an SSH key of a user in Gerrit."""
335331

336332
def get_parser(self, prog_name):
337-
parser = super(AccountSSHKeyDelete, self).get_parser(prog_name)
333+
parser = super().get_parser(prog_name)
338334
parser.add_argument(
339335
"account_id", metavar="account-identifier", help="Account identifier."
340336
)
@@ -370,7 +366,7 @@ class AccountMembershipList(AccountMixIn, base.BaseListCommand):
370366
)
371367

372368
def get_parser(self, prog_name):
373-
parser = super(AccountMembershipList, self).get_parser(prog_name)
369+
parser = super().get_parser(prog_name)
374370
parser.add_argument(
375371
"account_id", metavar="account-identifier", help="Account identifier."
376372
)
@@ -388,7 +384,7 @@ class AccountEmailAdd(AccountMixIn, base.BaseShowCommand):
388384
columns = ("email", "preferred", "pending_confirmation")
389385

390386
def get_parser(self, app_name):
391-
parser = super(AccountEmailAdd, self).get_parser(app_name)
387+
parser = super().get_parser(app_name)
392388
parser.add_argument("-e", "--email", required=True, help="Account email.")
393389
parser.add_argument(
394390
"--preferred", action="store_true", help="Set email address as preferred."
@@ -416,7 +412,7 @@ class AccountEmailDelete(AccountMixIn, base.BaseCommand):
416412
"""Deletes an email address of an account in Gerrit."""
417413

418414
def get_parser(self, prog_name):
419-
parser = super(AccountEmailDelete, self).get_parser(prog_name)
415+
parser = super().get_parser(prog_name)
420416
parser.add_argument(
421417
"account_id", metavar="account-identifier", help="Account identifier."
422418
)

gerritclient/commands/base.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class BaseCommand(command.Command, abc.ABC):
2929
"""Base Gerrit Code Review Client command."""
3030

3131
def __init__(self, *args, **kwargs):
32-
super(BaseCommand, self).__init__(*args, **kwargs)
32+
super().__init__(*args, **kwargs)
3333
self.client = client.get_client(self.entity_name, VERSION)
3434

3535
@property
@@ -98,7 +98,7 @@ def columns(self):
9898
pass
9999

100100
def get_parser(self, app_name):
101-
parser = super(BaseShowCommand, self).get_parser(app_name)
101+
parser = super().get_parser(app_name)
102102

103103
parser.add_argument(
104104
"entity_id",
@@ -122,13 +122,11 @@ class BaseCreateCommand(BaseShowCommand, abc.ABC):
122122
@staticmethod
123123
def get_file_path(file_path):
124124
if not utils.file_exists(file_path):
125-
raise argparse.ArgumentTypeError(
126-
f"File '{file_path}' does not exist"
127-
)
125+
raise argparse.ArgumentTypeError(f"File '{file_path}' does not exist")
128126
return file_path
129127

130128
def get_parser(self, prog_name):
131-
parser = super(BaseCreateCommand, self).get_parser(prog_name)
129+
parser = super().get_parser(prog_name)
132130
parser.add_argument(
133131
"--file", type=self.get_file_path, help="File with metadata to be uploaded."
134132
)
@@ -164,7 +162,7 @@ def action_type(self):
164162
pass
165163

166164
def get_parser(self, prog_name):
167-
parser = super(BaseEntitySetState, self).get_parser(prog_name)
165+
parser = super().get_parser(prog_name)
168166
parser.add_argument(
169167
"entity_id",
170168
metavar=f"{self.entity_name}-identifier",
@@ -181,7 +179,7 @@ def take_action(self, parsed_args):
181179

182180
class BaseDownloadCommand(BaseCommand, abc.ABC):
183181
def get_parser(self, prog_name):
184-
parser = super(BaseDownloadCommand, self).get_parser(prog_name)
182+
parser = super().get_parser(prog_name)
185183
parser.add_argument(
186184
"-f",
187185
"--format",

gerritclient/commands/change.py

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class ChangeList(ChangeMixIn, base.BaseListCommand):
9999
"""Queries changes visible to the caller."""
100100

101101
def get_parser(self, prog_name):
102-
parser = super(ChangeList, self).get_parser(prog_name)
102+
parser = super().get_parser(prog_name)
103103
parser.add_argument("query", nargs="+", help="Query string.")
104104
parser.add_argument(
105105
"-l",
@@ -140,7 +140,7 @@ class ChangeShow(ChangeMixIn, base.BaseShowCommand):
140140
"""Retrieves a change."""
141141

142142
def get_parser(self, app_name):
143-
parser = super(ChangeShow, self).get_parser(app_name)
143+
parser = super().get_parser(app_name)
144144
parser.add_argument(
145145
"-a",
146146
"--all",
@@ -190,13 +190,11 @@ class ChangeCreate(ChangeMixIn, base.BaseCommand, base.show.ShowOne):
190190
@staticmethod
191191
def get_file_path(file_path):
192192
if not utils.file_exists(file_path):
193-
raise argparse.ArgumentTypeError(
194-
f"File '{file_path}' does not exist"
195-
)
193+
raise argparse.ArgumentTypeError(f"File '{file_path}' does not exist")
196194
return file_path
197195

198196
def get_parser(self, prog_name):
199-
parser = super(ChangeCreate, self).get_parser(prog_name)
197+
parser = super().get_parser(prog_name)
200198
parser.add_argument(
201199
"file", type=self.get_file_path, help="File with metadata of a new change."
202200
)
@@ -257,7 +255,7 @@ class ChangeRevert(BaseChangeAction):
257255
parameters = ("message",)
258256

259257
def get_parser(self, app_name):
260-
parser = super(ChangeRevert, self).get_parser(app_name)
258+
parser = super().get_parser(app_name)
261259
parser.add_argument(
262260
"-m",
263261
"--message",
@@ -275,7 +273,7 @@ class ChangeMove(BaseChangeAction):
275273
parameters = ("branch", "message")
276274

277275
def get_parser(self, app_name):
278-
parser = super(ChangeMove, self).get_parser(app_name)
276+
parser = super().get_parser(app_name)
279277
parser.add_argument("-b", "--branch", required=True, help="Destination branch.")
280278
parser.add_argument(
281279
"-m", "--message", help="A message to be posted in this change's comments."
@@ -292,7 +290,7 @@ class ChangeSubmit(BaseChangeAction):
292290
parameters = ("on_behalf_of", "notify")
293291

294292
def get_parser(self, app_name):
295-
parser = super(ChangeSubmit, self).get_parser(app_name)
293+
parser = super().get_parser(app_name)
296294
parser.add_argument(
297295
"--on-behalf-of", help="Submit the change on behalf of the given user."
298296
)
@@ -315,7 +313,7 @@ class ChangeRebase(BaseChangeAction):
315313
parameters = ("parent",)
316314

317315
def get_parser(self, app_name):
318-
parser = super(ChangeRebase, self).get_parser(app_name)
316+
parser = super().get_parser(app_name)
319317
parser.add_argument("-p", "--parent", help="The new parent revision.")
320318
return parser
321319

@@ -327,7 +325,7 @@ class ChangeDelete(ChangeMixIn, base.BaseCommand):
327325
"""Deletes a change."""
328326

329327
def get_parser(self, prog_name):
330-
parser = super(ChangeDelete, self).get_parser(prog_name)
328+
parser = super().get_parser(prog_name)
331329
parser.add_argument(
332330
"change_id", metavar="change-identifier", help="Change identifier."
333331
)
@@ -357,7 +355,7 @@ class ChangeTopicSet(ChangeMixIn, base.BaseShowCommand):
357355
columns = ("topic",)
358356

359357
def get_parser(self, app_name):
360-
parser = super(ChangeTopicSet, self).get_parser(app_name)
358+
parser = super().get_parser(app_name)
361359
parser.add_argument("-t", "--topic", required=True, help="Topic of a change.")
362360
return parser
363361

@@ -395,7 +393,7 @@ class ChangeAssigneeHistoryShow(ChangeMixIn, base.BaseListCommand):
395393
columns = ("_account_id", "name", "email", "username")
396394

397395
def get_parser(self, prog_name):
398-
parser = super(ChangeAssigneeHistoryShow, self).get_parser(prog_name)
396+
parser = super().get_parser(prog_name)
399397
parser.add_argument(
400398
"change_id", metavar="change-identifier", help="Change identifier."
401399
)
@@ -413,7 +411,7 @@ class ChangeAssigneeSet(ChangeMixIn, base.BaseShowCommand):
413411
columns = ("_account_id", "name", "email", "username")
414412

415413
def get_parser(self, app_name):
416-
parser = super(ChangeAssigneeSet, self).get_parser(app_name)
414+
parser = super().get_parser(app_name)
417415
parser.add_argument(
418416
"-a",
419417
"--account",
@@ -441,7 +439,7 @@ class ChangeDraftPublish(ChangeMixIn, base.BaseCommand):
441439
"""Publishes a draft change."""
442440

443441
def get_parser(self, prog_name):
444-
parser = super(ChangeDraftPublish, self).get_parser(prog_name)
442+
parser = super().get_parser(prog_name)
445443
parser.add_argument(
446444
"change_id", metavar="change-identifier", help="Change identifier."
447445
)
@@ -467,7 +465,7 @@ class ChangeIndex(ChangeMixIn, base.BaseCommand):
467465
"""Adds or updates the change in the secondary index."""
468466

469467
def get_parser(self, prog_name):
470-
parser = super(ChangeIndex, self).get_parser(prog_name)
468+
parser = super().get_parser(prog_name)
471469
parser.add_argument(
472470
"change_id", metavar="change-identifier", help="Change identifier."
473471
)
@@ -486,7 +484,7 @@ class ChangeCommentList(ChangeCommentMixIn, base.BaseListCommand):
486484
"""Lists the published comments of all revisions of the change."""
487485

488486
def get_parser(self, prog_name):
489-
parser = super(ChangeCommentList, self).get_parser(prog_name)
487+
parser = super().get_parser(prog_name)
490488
parser.add_argument(
491489
"change_id", metavar="change-identifier", help="Change identifier."
492490
)
@@ -531,7 +529,7 @@ class ChangeFix(ChangeMixIn, base.BaseShowCommand):
531529
"""
532530

533531
def get_parser(self, app_name):
534-
parser = super(ChangeFix, self).get_parser(app_name)
532+
parser = super().get_parser(app_name)
535533
parser.add_argument(
536534
"--delete-patchset",
537535
action="store_true",

0 commit comments

Comments
 (0)