Infer Ruff target-version from requires-python#150
Merged
Conversation
Now that the minimum is Python 3.10, switch to PEP 604 unions (X | None) and PEP 585 builtin generics (list[str]) and drop the corresponding typing imports. Applied automatically via ruff's pyupgrade rules (UP006, UP035, UP045, UP007). This is a prerequisite for letting ruff infer its target version from requires-python. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Drop the hardcoded target-version from the Ruff config. When it is unset, Ruff derives the minimum supported Python version from the project's requires-python (>=3.10), so there is no second place to keep in sync when the supported range changes. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR aligns Ruff’s Python targeting with the project’s declared supported Python range (3.10+) by relying on project.requires-python, and applies the resulting Ruff-driven type-hint modernizations across the codebase.
Changes:
- Modernize type annotations to Python 3.10+ syntax (PEP 604 unions, PEP 585 built-in generics) and clean up related
typingimports. - Remove the hardcoded Ruff
target-versionso Ruff infers it fromrequires-pythoninpyproject.toml.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/labelle/lib/utils.py | Switch typing imports/annotations to collections.abc and built-in generics. |
| src/labelle/lib/render_engines/horizontally_combined.py | Use collections.abc.Sequence instead of typing.Sequence. |
| src/labelle/lib/font_config.py | Update dict/list/optional types to Python 3.10+ syntax. |
| src/labelle/lib/config_file.py | Update return type to `dict[str, Any] |
| src/labelle/lib/barcode_writer.py | Update list type annotation to list[str]. |
| src/labelle/lib/barcode_to_image.py | Update list/tuple/union annotations to Python 3.10+ syntax. |
| src/labelle/gui/q_render.py | Update optional QWidget annotation to `QWidget |
| src/labelle/gui/q_labels_list.py | Update Optional/List annotations to ` |
| src/labelle/gui/q_actions.py | Update optional types to ` |
| src/labelle/gui/gui.py | Update optional image type to `Image.Image |
| src/labelle/cli/cli.py | Update Typer-exposed parameter annotations to Python 3.10+ syntax and built-in generics. |
| pyproject.toml | Remove Ruff target-version to infer it from project.requires-python. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up to #148. With the minimum Python now at 3.10, the Ruff
target-versionwas a second place to keep in sync withrequires-python. Ruff derives the target fromproject.requires-pythonwhentarget-versionis unset, so this PR drops the hardcoded line.Removing it raises Ruff's inferred target from
py38topy310, which enables the pyupgrade rules already in theselectlist (UP006/UP035/UP045/UP007). The resulting modernization is applied in its own commit.Commits (atomic)
X | None) and PEP 585 builtin generics (list[str]), dropping the correspondingtypingimports. Applied automatically via Ruff--fix --unsafe-fixes, thenruff format. 11 files, no manual edits.Splitting these keeps the mechanical churn separate from the config decision, and each commit is independently lint-clean.
Verification
ruff checkandruff format --checkpass on all tracked sources.mypypasses (pre-commit).labelle --versionandlabelle --helpexit 0, and typer correctly introspects the new annotations (e.g.list[str] | None→TEXT,int | None→INTEGER). The--fontand other options render as before.🤖 Generated with Claude Code