Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add a fix for redefinition-while-unused #9419

Merged
merged 2 commits into from
Jan 9, 2024
Merged

Add a fix for redefinition-while-unused #9419

merged 2 commits into from
Jan 9, 2024

Conversation

charliermarsh
Copy link
Member

@charliermarsh charliermarsh commented Jan 7, 2024

Summary

This PR enables Ruff to remove redefined imports, as in:

import os
import os

print(os)

Previously, Ruff would flag F811 on the second import os, but couldn't fix it.

For now, this fix is marked as safe, but only available in preview.

Closes #3477.

@charliermarsh charliermarsh added the fixes Related to suggested fixes for violations label Jan 7, 2024
Copy link
Contributor

github-actions bot commented Jan 7, 2024

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

ℹ️ ecosystem check detected linter changes. (+0 -0 violations, +4 -0 fixes in 1 projects; 42 projects unchanged)

aws/aws-sam-cli (+0 -0 violations, +4 -0 fixes)

ruff check --no-cache --exit-zero --preview

- tests/unit/commands/deploy/test_deploy_context.py:10:47: F811 Redefinition of unused `DeployFailedError` from line 8
+ tests/unit/commands/deploy/test_deploy_context.py:10:47: F811 [*] Redefinition of unused `DeployFailedError` from line 8
- tests/unit/local/docker/test_lambda_image.py:8:27: F811 Redefinition of unused `parameterized` from line 5
+ tests/unit/local/docker/test_lambda_image.py:8:27: F811 [*] Redefinition of unused `parameterized` from line 5

Changes by rule (1 rules affected)

code total + violation - violation + fix - fix
F811 4 0 0 4 0

@zanieb
Copy link
Member

zanieb commented Jan 8, 2024

I think it can be safe if we merge #9418?

Probably? Seems safer to start this way.

@charliermarsh
Copy link
Member Author

@zanieb - I'm not sure how to justify or explain that the fix is unsafe though, now that we removed branching. It should always be safe?

@zanieb
Copy link
Member

zanieb commented Jan 8, 2024

@charliermarsh I guess so! I can't think of a case. We could gate the fix with preview for now?

@charliermarsh charliermarsh added the preview Related to preview mode features label Jan 9, 2024
@charliermarsh charliermarsh enabled auto-merge (squash) January 9, 2024 00:23
@charliermarsh charliermarsh merged commit 84ab21f into main Jan 9, 2024
16 checks passed
@charliermarsh charliermarsh deleted the charlie/F811 branch January 9, 2024 00:29
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
fixes Related to suggested fixes for violations preview Related to preview mode features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

I want ruff to fix F811 error.
2 participants