chore: disallow relative imports#8403
Conversation
d4f4d3e to
5224e68
Compare
5224e68 to
da61683
Compare
|
Seems there's issue on installer test, could you help to take another look |
| "F", # Pyflakes | ||
| "PL", # pylint | ||
| "I", # isort | ||
| "TID", # flake8-tidy-imports |
There was a problem hiding this comment.
[GENERAL] The PR enables the TID ruff rule with ban-relative-imports = "all" and converts relative imports to absolute across 39 files. However, 8 __init__.py files under samcli/commands/ still use relative imports and are not converted:
samcli/commands/build/__init__.pysamcli/commands/delete/__init__.pysamcli/commands/deploy/__init__.pysamcli/commands/docs/__init__.pysamcli/commands/logs/__init__.pysamcli/commands/package/__init__.pysamcli/commands/publish/__init__.pysamcli/commands/sync/__init__.py
Each of these contains from .command import cli # noqa. The bare # noqa comment (originally there to suppress F401 for the re-export) silently suppresses the new TID252 violation as well, so the lint won't fail. But this leaves the migration incomplete — the # noqa is now masking a banned pattern rather than just suppressing an unused-import warning.
Consider converting these files to absolute imports too (e.g., from samcli.commands.build.command import cli # noqa: F401) and narrowing the bare # noqa to # noqa: F401 so TID252 is actually enforced everywhere.
Which issue(s) does this change fix?
Why is this change necessary?
Updating the linting configuration in SAM CLI to disallow relative imports.
How does it address the issue?
Adding updated rules in the linting configuration in
pyproject.tomlto disallow relative imports. Updating all instances of relative imports to absolute formake prto pass.What side effects does this change have?
None.
Mandatory Checklist
PRs will only be reviewed after checklist is complete
make prpassesmake update-reproducible-reqsif dependencies were changedBy submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.