Skip to content

Ruff new rules - #447

Merged
don-vip merged 30 commits into
toolforge:masterfrom
don-vip:ruff-new-rules
Oct 23, 2026
Merged

don-vip merged 30 commits into
toolforge:masterfrom
don-vip:ruff-new-rules

Conversation

@don-vip

@don-vip don-vip commented Oct 23, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

don-vip and others added 30 commits October 23, 2026 23:23
Classes inherit from object implicitly in Python 3.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Use the zero-argument form of super().

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
IOError is an alias of OSError since Python 3.3.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Remove redundant parentheses.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Remove a pass statement that follows other statements.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Don't explicitly return None from a function that never returns anything else.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Use the explicit regex flag names (re.IGNORECASE rather than re.I).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Use the datetime.UTC alias (Python 3.11+).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Use the built-in set type in annotations instead of typing.Set.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Import Iterable from collections.abc rather than typing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Write Optional[X] as X | None.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Use f-strings instead of str.format().

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sort the imports: standard library, third-party, then first-party
modules, alphabetically. Aliased imports are combined with the others
(combine-as-imports). The order change has no side effect: every module
of the package still imports.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Iterate over the keys or values of a dict directly when the other half is unused.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Use a dict comprehension instead of dict() around a generator.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
math.floor() already returns an int.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Name unused unpacked values _.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Merge nested if statements that have no else branch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Default the preserve argument to None instead of a shared dict.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Annotate the shared encoding settings as a ClassVar.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Bind the list of warnings of the current upload attempt to the callback that fills it. It was already used within the same attempt only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Open files with a with statement, which closes them even on error.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Pass check=False explicitly: every call already checks the return code itself.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Use start_new_session=True, which runs setsid() in the child like preexec_fn=os.setsid did, without preexec_fn's risk of deadlocks in a multithreaded process (the output of ffmpeg is read from a thread).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Replace %-formatting with f-strings or str.format(). The output of the changed functions (sources, licenses, dates, sizes) is unchanged for sample inputs; %d becomes int() to keep truncating floats.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Log the errors that were silently ignored (stats updates, stats lock) instead of hiding them. The behaviour is unchanged: the task or the API call still goes on.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Catch narrower exceptions where possible (subtitle decoding), log the others with their traceback, and mark the intentional ones: subtitle errors are reported to the user but must not fail the upload, and a task status that can't be read is shown with its traceback.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Exempt the user-config.py files: Pywikibot requires this exact file name.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
All the rules that Ruff 0.16+ enables by default now pass, so use them
instead of the explicit list, plus the pycodestyle and pyflakes rules
that are no longer in it. This also fixes the two violations that show
up with the complete set: an unnecessary encode("utf-8") argument
(UP012) and an unused noqa directive (RUF100).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Ruff only checks the executable bit on Unix, so this was missed on
Windows. Modules and configuration files are imported, never run
directly: drop their shebang. The scripts in utils/ keep theirs and
become executable (cron and the Toolforge job still call them with an
explicit interpreter).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@don-vip
don-vip merged commit 4221de3 into toolforge:master Oct 23, 2026
4 checks passed
@don-vip
don-vip deleted the ruff-new-rules branch October 23, 2026 23:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant