Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGES/1349.contrib.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Enabled the ``PLC0415`` (import-outside-top-level) rule in
``[tool.ruff.lint]``. Function-scoped imports must now opt in
with ``# noqa: PLC0415`` plus a comment explaining the reason
(typically avoiding a heavy optional dependency at import time).
This catches a pattern that LLM contributors frequently introduce.
There are currently no opt-outs in the tree, so the rule is
enforced everywhere ``ruff check`` runs
-- by :user:`bdraco`.
6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ select = [
# (ruff format) and the import sorter (ruff check --select I) come
# from the same tool and rev.
"I",
# Imports must live at the top of the module. Late/inside-function
# imports must be opted into explicitly with `# noqa: PLC0415` and a
# comment explaining why (e.g. avoiding a heavy optional dependency
# in the import path). Enforced because AI-assisted contributions
# frequently introduce function-scoped imports that are unnecessary.
"PLC0415",
# pyupgrade: enforce modern Python syntax for the current
# ``target-version`` (currently py310).
"UP",
Expand Down
Loading