Skip to content

Add a fix for redefinition-while-unused - #9419

Merged
charliermarsh merged 2 commits into
mainfrom
charlie/F811
Jan 9, 2024
Merged

charliermarsh merged 2 commits into
mainfrom
charlie/F811

Conversation

@charliermarsh

@charliermarsh charliermarsh commented Jan 7, 2024 •

Copy link
Copy Markdown
Member

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
@charliermarsh
charliermarsh requested a review from zanieb January 7, 2024 01:59
@github-actions

github-actions Bot commented Jan 7, 2024 •

Copy link
Copy Markdown
Contributor

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

zanieb commented Jan 8, 2024

Copy link
Copy Markdown
Member

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

Probably? Seems safer to start this way.

@charliermarsh

Copy link
Copy Markdown
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

zanieb commented Jan 8, 2024

Copy link
Copy Markdown
Member

@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
@charliermarsh
charliermarsh deleted the charlie/F811 branch January 9, 2024 00:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in 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