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

Incorrect len(x) > 0 suggestion #31

Closed
TylerYep opened this issue Oct 1, 2022 · 1 comment · Fixed by #32
Closed

Incorrect len(x) > 0 suggestion #31

TylerYep opened this issue Oct 1, 2022 · 1 comment · Fixed by #32
Assignees
Labels
bug Something isn't working

Comments

@TylerYep
Copy link

TylerYep commented Oct 1, 2022

This suggestion changes the resulting code:

x = ""
is_negative = len(x) > 0 and x[0] == "-"   # Output: False

# Violates [FURB115]: Use `x` instead of `len(x) > 0`

x = ""
is_negative = x and x[0] == "-"   # Output: ""
@dosisod dosisod self-assigned this Oct 1, 2022
@dosisod dosisod added the bug Something isn't working label Oct 1, 2022
@dosisod
Copy link
Owner

dosisod commented Oct 1, 2022

Yes, this is most definitely a bug. Refurb should check to make sure that x is being used in a situation where a bool is expected, like an if block.

Thank you for reporting this!

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants