Repository: wemake-services/wemake-python-styleguide

Issue:
False positive for `WPS345 Found meaningless number operation`
# Bug report

<!--
Hi, thanks for submitting a bug. We appreciate that.

But, we will need some information about what's wrong to help you.
-->

## What's wrong

False positive for `1 / some`:

```
  13:12    WPS345 Found meaningless number operation
  return 1 / number
```

<!-- Describe what is not working. Please, attach a traceback. -->

## How is that should be

`1 / ANY` should be allowed.




Discussion:
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 =)
@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! 👍 
Thank you very much!
plz, assign this issue to me on the GitHub UI. Thank you =)

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.
```python
@pytest.mark.parametrize('expression', [
    '1 / other',
    '1 / 11',
])
```

Are both correct according to this rule. But:

```python
@pytest.mark.parametrize('expression', [
    'other / 1',
    '11 / 1',
])
```

Are not correct.

Resolving patch:
diff --git a/wemake_python_styleguide/visitors/ast/operators.py b/wemake_python_styleguide/visitors/ast/operators.py
--- a/wemake_python_styleguide/visitors/ast/operators.py
+++ b/wemake_python_styleguide/visitors/ast/operators.py
@@ -101,6 +101,9 @@ def _check_useless_math_operator(
         left: ast.AST,
         right: Optional[ast.AST] = None,
     ) -> None:
+        if isinstance(left, ast.Num) and right:
+            if left.n == 1:
+                left = None
         non_negative_numbers = self._get_non_negative_nodes(left, right)
 
         for number in non_negative_numbers:


Test patch:
diff --git a/tests/test_visitors/test_ast/test_operators/test_useless_math.py b/tests/test_visitors/test_ast/test_operators/test_useless_math.py
--- a/tests/test_visitors/test_ast/test_operators/test_useless_math.py
+++ b/tests/test_visitors/test_ast/test_operators/test_useless_math.py
@@ -164,3 +164,44 @@ def test_useful_math(
     visitor.run()
 
     assert_errors(visitor, [])
+
+
+@pytest.mark.parametrize('expression', [
+    '1 / other',
+    '1 / 11',
+    '1 / 1.1',
+])
+def test_one_to_divide(
+    assert_errors,
+    parse_ast_tree,
+    expression,
+    default_options,
+):
+    """Testing that `1 / any number` is the correct expression."""
+    tree = parse_ast_tree(expression)
+
+    visitor = UselessOperatorsVisitor(default_options, tree=tree)
+    visitor.run()
+
+    assert_errors(visitor, [])
+
+
+@pytest.mark.parametrize('expression', [
+    '1 / 1',
+    '2 / 1',
+    '3.3 / 1',
+    'other / 1',
+])
+def test_divide_by_one(
+    assert_errors,
+    parse_ast_tree,
+    expression,
+    default_options,
+):
+    """Testing an error when we divide by one."""
+    tree = parse_ast_tree(expression)
+
+    visitor = UselessOperatorsVisitor(default_options, tree=tree)
+    visitor.run()
+
+    assert_errors(visitor, [MeaninglessNumberOperationViolation])