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

FURB171 Does not trigger when calling set(...) #15792

Open
naslundx opened this issue Jan 28, 2025 · 4 comments · May be fixed by #15793
Open

FURB171 Does not trigger when calling set(...) #15792

naslundx opened this issue Jan 28, 2025 · 4 comments · May be fixed by #15793
Labels
preview Related to preview mode features rule Implementing or modifying a lint rule

Comments

@naslundx
Copy link
Contributor

naslundx commented Jan 28, 2025

Description

Minimal code snippet:

if 1 in {1}:  # This triggers
    print("Single-element set")

if 1 in set([1]):  # This does not, but is equivalent
    print("Single-element set")

Command:
ruff check --isolated testfile.py --select FURB171 --preview

No other settings.

Ruff version 0.9.3.

@InSyncWithFoo
Copy link
Contributor

These two are not equivalent:

>>> set(1)
Traceback (most recent call last):
  File "<python-input-0>", line 1, in <module>
    set(1)
    ~~~^^^
TypeError: 'int' object is not iterable

@naslundx
Copy link
Contributor Author

Sorry about that. Edited the original post, it should be set([1]). Indeed:

>>> set([1]) == {1}
True

@dylwil3
Copy link
Collaborator

dylwil3 commented Jan 29, 2025

I'm not sure if the scope of the rule should be extended to include composite constructions of singleton collections. There would be a lot of special cases to consider and it's not clear to me how one would draw the line for what should or shouldn't be considered. Already in this case if we add set([1]) shouldn't we also add set("a") or set((1,))

@dylwil3 dylwil3 added rule Implementing or modifying a lint rule needs-decision Awaiting a decision from a maintainer labels Jan 29, 2025
@dylwil3
Copy link
Collaborator

dylwil3 commented Jan 30, 2025

I'm not sure if the scope of the rule should be extended to include composite constructions of singleton collections. There would be a lot of special cases to consider and it's not clear to me how one would draw the line for what should or shouldn't be considered. Already in this case if we add set([1]) shouldn't we also add set("a") or set((1,))

@AlexWaygood has convinced me that this extension in scope has more pros than cons - thanks for suggesting it, and sorry for delaying things a bit!

@dylwil3 dylwil3 added preview Related to preview mode features and removed needs-decision Awaiting a decision from a maintainer labels Jan 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
preview Related to preview mode features rule Implementing or modifying a lint rule
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants