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

False positive for WPS345 Found meaningless number operation #775

Closed
sobolevn opened this issue Aug 17, 2019 · 5 comments · Fixed by #786
Closed

False positive for WPS345 Found meaningless number operation #775

sobolevn opened this issue Aug 17, 2019 · 5 comments · Fixed by #786
Assignees
Labels
bug Something isn't working help wanted Extra attention is needed level:starter Good for newcomers pr-merged

Comments

@sobolevn
Copy link
Member

Bug report

What's wrong

False positive for 1 / some:

  13:12    WPS345 Found meaningless number operation
  return 1 / number

How is that should be

1 / ANY should be allowed.

@sobolevn sobolevn added bug Something isn't working help wanted Extra attention is needed level:starter Good for newcomers labels Aug 17, 2019
@sobolevn sobolevn added this to the Version 0.12.x milestone Aug 17, 2019
@serhii73
Copy link
Contributor

Hello, @sobolevn. I can do it.
Can you tell me more about this task?
Because I do not fully understand when False-positive happen.
Thank you =)

@sobolevn
Copy link
Member Author

@serhii73 here's the full explanation:

  1. This code: https://github.com/wemake-services/wemake-python-styleguide/blob/master/wemake_python_styleguide/visitors/ast/operators.py#L98-L111 produces incorrect result. It treats 1 / some as useless math operation. But it is not. You can and should be able to use it.
  2. These tests do not check it: https://github.com/wemake-services/wemake-python-styleguide/blob/master/tests/test_visitors/test_ast/test_operators/test_useless_math.py

Things we need to do:

  1. Allow N / operations, they should be allowed for N != 0
  2. Test these cases explicitly in a regression test

Thanks for your help! I appreciate that! 👍

@serhii73
Copy link
Contributor

Thank you very much!
plz, assign this issue to me on the GitHub UI. Thank you =)

@serhii73
Copy link
Contributor

Sorry @sobolevn can you help me?

@pytest.mark.parametrize('expression', [
........
])

I don't understand how to right write a list of expressions.

@pytest.mark.parametrize('expression', [
    '1 / other',
])

or

@pytest.mark.parametrize('expression', [
    '1 / 11',
])

it is not right.

@sobolevn
Copy link
Member Author

@pytest.mark.parametrize('expression', [
    '1 / other',
    '1 / 11',
])

Are both correct according to this rule. But:

@pytest.mark.parametrize('expression', [
    'other / 1',
    '11 / 1',
])

Are not correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed level:starter Good for newcomers pr-merged
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants