aboutsummaryrefslogtreecommitdiff
path: root/tests/functional/s/super/superfluous_parens.py
blob: 22c4c3ab4b3b4665fb0d8a86fd774f258c8139d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
"""Test the superfluous-parens warning."""
# pylint: disable=unneeded-not, unnecessary-comprehension, missing-function-docstring, invalid-name, fixme
# pylint: disable=import-error, missing-class-docstring, too-few-public-methods
import numpy as np
A = 3
if (A == 5):  # [superfluous-parens]
    pass
if not (A == 5):  # [superfluous-parens]
    pass
if not (3 or 5):
    pass
for (x) in (1, 2, 3):  # [superfluous-parens]
    print(x)
if (1) in (1, 2, 3):  # [superfluous-parens]
    pass
if (1, 2) in (1, 2, 3):
    pass
DICT = {'a': 1, 'b': 2}
del(DICT['b'])  # [superfluous-parens]
del DICT['a']

B = [x for x in ((3, 4))]
C = [x for x in ((3, 4) if 1 > 0 else (5, 6))]
D = [x for x in ((3, 4) if 1 > 0 else ((5, 6)))]
E = [x for x in ((3, 4) if 1 > 0 else ((((5, 6)))))]

# Test assertions
F = "Version 1.0"
G = "1.0"
assert "Version " + G in F
assert ("Version " + G) in F # [superfluous-parens]

# Test assignment
H = 2 + (5 * 3)
NUMS_LIST = ['1', '2', '3']
NUMS_SET = {'1', '2', '3'}
NUMS_DICT = {'1': 1, '2': 2, '3': 3}
I = tuple(x for x in ((a, str(a)) for a in ()))

# Test functions
def function_A():
    return (x for x in ((3, 4)))

def function_B(var):
    return (var.startswith(('A', 'B', 'C')) or var == 'D')

# TODO: Test string combinations, see https://github.com/PyCQA/pylint/issues/4792
# Lines 45, 46 & 47 should raise the superfluous-parens message
J = "TestString"
K = ("Test " + "String")
L = ("Test " + "String") in I
assert "" + ("Version " + "String") in I

# Test numpy
def function_numpy_A(var_1: int, var_2: int) -> np.ndarray:
    result = (((var_1 & var_2)) > 0)
    return result.astype(np.float32)

def function_numpy_B(var_1: int, var_2: int) -> np.ndarray:
    return (((var_1 & var_2)) > 0).astype(np.float32)

# Test Class
class ClassA:
    keys = []

    def __iter__(self):
        return ((k, getattr(self, k)) for k in self.keys)