Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

SIM101 lint and fix is sometimes incorrect #7964

Closed
Zac-HD opened this issue Oct 15, 2023 · 2 comments
Closed

SIM101 lint and fix is sometimes incorrect #7964

Zac-HD opened this issue Oct 15, 2023 · 2 comments

Comments

@Zac-HD
Copy link

Zac-HD commented Oct 15, 2023

The SIM101 rule suggests replacing isinstance(a. b) or isinstance(a, c) with isinstance(a, (b, c)) - but the lint and autofix also trigger when there is an intermediate term in the or-expression. This is a problem because code can (and does) rely on short-circuiting evaluation in some such cases. For example, ruff --isolated --select=SIM101 --fix demo.py will break:

x = isinstance("", int) or True or isinstance("", undefined_name)
# x = isinstance("", (int, undefined_name)) or True  # incorrect fix!

I found this while experimenting with ruff in shed, which has a similar fixer.

@zanieb
Copy link
Member

zanieb commented Oct 15, 2023

Hey, thanks for the issue! This fix as marked unsafe and will not be applied by default in the upcoming release. See #7901 and #7769 for details.

@zanieb zanieb closed this as completed Oct 15, 2023
@Zac-HD
Copy link
Author

Zac-HD commented Oct 17, 2023

Actual fix was in #7798 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants