Method: pylint.checkers.base.basic_error_checker.BasicErrorChecker._check_redefinition
Calls: 5009, Exceptions: 5009, Paths: 13Back
Path 1: 4861 calls (0.97)
'function' (1728) 'method' (1649) 'class' (1484)
FunctionDef (3323) ClassDef (1484) AsyncFunctionDef (54)
GeneratorExit (4861)
1def _check_redefinition(
2 self, redeftype: str, node: nodes.Call | nodes.FunctionDef
3 ) -> None:
4 """Check for redefinition of a function / method / class name."""
5 parent_frame = node.parent.frame(future=True)
6
7 # Ignore function stubs created for type information
8 redefinitions = [
9 i
10 for i in parent_frame.locals[node.name]
11 if not (isinstance(i.parent, nodes.AnnAssign) and i.parent.simple)
12 ]
13 defined_self = next(
14 (local for local in redefinitions if not utils.is_overload_stub(local)),
15 node,
16 )
17 if defined_self is not node and not astroid.are_exclusive(node, defined_self):
18 # Additional checks for methods which are not considered
19 # redefined, since they are already part of the base API.
20 if (
21 isinstance(parent_frame, nodes.ClassDef)
22 and node.name in REDEFINABLE_METHODS
23 ):
24 return
25
26 # Skip typing.overload() functions.
27 if utils.is_overload_stub(node):
28 return
29
30 # Exempt functions redefined on a condition.
31 if isinstance(node.parent, nodes.If):
32 # Exempt "if not <func>" cases
33 if (
34 isinstance(node.parent.test, nodes.UnaryOp)
35 and node.parent.test.op == "not"
36 and isinstance(node.parent.test.operand, nodes.Name)
37 and node.parent.test.operand.name == node.name
38 ):
39 return
40
41 # Exempt "if <func> is not None" cases
42 # pylint: disable=too-many-boolean-expressions
43 if (
44 isinstance(node.parent.test, nodes.Compare)
45 and isinstance(node.parent.test.left, nodes.Name)
46 and node.parent.test.left.name == node.name
47 and node.parent.test.ops[0][0] == "is"
48 and isinstance(node.parent.test.ops[0][1], nodes.Const)
49 and node.parent.test.ops[0][1].value is None
50 ):
51 return
52
53 # Check if we have forward references for this node.
54 try:
55 redefinition_index = redefinitions.index(node)
56 except ValueError:
57 pass
58 else:
59 for redefinition in redefinitions[:redefinition_index]:
60 inferred = utils.safe_infer(redefinition)
61 if (
62 inferred
63 and isinstance(inferred, astroid.Instance)
64 and inferred.qname() == TYPING_FORWARD_REF_QNAME
65 ):
66 return
67
68 dummy_variables_rgx = self.linter.config.dummy_variables_rgx
69 if dummy_variables_rgx and dummy_variables_rgx.match(node.name):
70 return
71 self.add_message(
72 "function-redefined",
73 node=node,
74 args=(redeftype, defined_self.fromlineno),
75 )
Path 2: 91 calls (0.02)
'function' (57) 'class' (34)
FunctionDef (57) ClassDef (34)
GeneratorExit (91)
1def _check_redefinition(
2 self, redeftype: str, node: nodes.Call | nodes.FunctionDef
3 ) -> None:
4 """Check for redefinition of a function / method / class name."""
5 parent_frame = node.parent.frame(future=True)
6
7 # Ignore function stubs created for type information
8 redefinitions = [
9 i
10 for i in parent_frame.locals[node.name]
11 if not (isinstance(i.parent, nodes.AnnAssign) and i.parent.simple)
12 ]
13 defined_self = next(
14 (local for local in redefinitions if not utils.is_overload_stub(local)),
15 node,
16 )
17 if defined_self is not node and not astroid.are_exclusive(node, defined_self):
18 # Additional checks for methods which are not considered
19 # redefined, since they are already part of the base API.
20 if (
21 isinstance(parent_frame, nodes.ClassDef)
22 and node.name in REDEFINABLE_METHODS
23 ):
24 return
25
26 # Skip typing.overload() functions.
27 if utils.is_overload_stub(node):
28 return
29
30 # Exempt functions redefined on a condition.
31 if isinstance(node.parent, nodes.If):
32 # Exempt "if not <func>" cases
33 if (
34 isinstance(node.parent.test, nodes.UnaryOp)
35 and node.parent.test.op == "not"
36 and isinstance(node.parent.test.operand, nodes.Name)
37 and node.parent.test.operand.name == node.name
38 ):
39 return
40
41 # Exempt "if <func> is not None" cases
42 # pylint: disable=too-many-boolean-expressions
43 if (
44 isinstance(node.parent.test, nodes.Compare)
45 and isinstance(node.parent.test.left, nodes.Name)
46 and node.parent.test.left.name == node.name
47 and node.parent.test.ops[0][0] == "is"
48 and isinstance(node.parent.test.ops[0][1], nodes.Const)
49 and node.parent.test.ops[0][1].value is None
50 ):
51 return
52
53 # Check if we have forward references for this node.
54 try:
55 redefinition_index = redefinitions.index(node)
56 except ValueError:
57 pass
58 else:
59 for redefinition in redefinitions[:redefinition_index]:
60 inferred = utils.safe_infer(redefinition)
61 if (
62 inferred
63 and isinstance(inferred, astroid.Instance)
64 and inferred.qname() == TYPING_FORWARD_REF_QNAME
65 ):
66 return
67
68 dummy_variables_rgx = self.linter.config.dummy_variables_rgx
69 if dummy_variables_rgx and dummy_variables_rgx.match(node.name):
70 return
71 self.add_message(
72 "function-redefined",
73 node=node,
74 args=(redeftype, defined_self.fromlineno),
75 )
Path 3: 20 calls (0.0)
'method' (20)
FunctionDef (20)
GeneratorExit (20)
1def _check_redefinition(
2 self, redeftype: str, node: nodes.Call | nodes.FunctionDef
3 ) -> None:
4 """Check for redefinition of a function / method / class name."""
5 parent_frame = node.parent.frame(future=True)
6
7 # Ignore function stubs created for type information
8 redefinitions = [
9 i
10 for i in parent_frame.locals[node.name]
11 if not (isinstance(i.parent, nodes.AnnAssign) and i.parent.simple)
12 ]
13 defined_self = next(
14 (local for local in redefinitions if not utils.is_overload_stub(local)),
15 node,
16 )
17 if defined_self is not node and not astroid.are_exclusive(node, defined_self):
18 # Additional checks for methods which are not considered
19 # redefined, since they are already part of the base API.
20 if (
21 isinstance(parent_frame, nodes.ClassDef)
22 and node.name in REDEFINABLE_METHODS
23 ):
24 return
25
26 # Skip typing.overload() functions.
27 if utils.is_overload_stub(node):
28 return
29
30 # Exempt functions redefined on a condition.
31 if isinstance(node.parent, nodes.If):
32 # Exempt "if not <func>" cases
33 if (
34 isinstance(node.parent.test, nodes.UnaryOp)
35 and node.parent.test.op == "not"
36 and isinstance(node.parent.test.operand, nodes.Name)
37 and node.parent.test.operand.name == node.name
38 ):
39 return
40
41 # Exempt "if <func> is not None" cases
42 # pylint: disable=too-many-boolean-expressions
43 if (
44 isinstance(node.parent.test, nodes.Compare)
45 and isinstance(node.parent.test.left, nodes.Name)
46 and node.parent.test.left.name == node.name
47 and node.parent.test.ops[0][0] == "is"
48 and isinstance(node.parent.test.ops[0][1], nodes.Const)
49 and node.parent.test.ops[0][1].value is None
50 ):
51 return
52
53 # Check if we have forward references for this node.
54 try:
55 redefinition_index = redefinitions.index(node)
56 except ValueError:
57 pass
58 else:
59 for redefinition in redefinitions[:redefinition_index]:
60 inferred = utils.safe_infer(redefinition)
61 if (
62 inferred
63 and isinstance(inferred, astroid.Instance)
64 and inferred.qname() == TYPING_FORWARD_REF_QNAME
65 ):
66 return
67
68 dummy_variables_rgx = self.linter.config.dummy_variables_rgx
69 if dummy_variables_rgx and dummy_variables_rgx.match(node.name):
70 return
71 self.add_message(
72 "function-redefined",
73 node=node,
74 args=(redeftype, defined_self.fromlineno),
75 )
Path 4: 17 calls (0.0)
'method' (17)
FunctionDef (17)
None (17)
GeneratorExit (17)
1def _check_redefinition(
2 self, redeftype: str, node: nodes.Call | nodes.FunctionDef
3 ) -> None:
4 """Check for redefinition of a function / method / class name."""
5 parent_frame = node.parent.frame(future=True)
6
7 # Ignore function stubs created for type information
8 redefinitions = [
9 i
10 for i in parent_frame.locals[node.name]
11 if not (isinstance(i.parent, nodes.AnnAssign) and i.parent.simple)
12 ]
13 defined_self = next(
14 (local for local in redefinitions if not utils.is_overload_stub(local)),
15 node,
16 )
17 if defined_self is not node and not astroid.are_exclusive(node, defined_self):
18 # Additional checks for methods which are not considered
19 # redefined, since they are already part of the base API.
20 if (
21 isinstance(parent_frame, nodes.ClassDef)
22 and node.name in REDEFINABLE_METHODS
23 ):
24 return
25
26 # Skip typing.overload() functions.
27 if utils.is_overload_stub(node):
28 return
29
30 # Exempt functions redefined on a condition.
31 if isinstance(node.parent, nodes.If):
32 # Exempt "if not <func>" cases
33 if (
34 isinstance(node.parent.test, nodes.UnaryOp)
35 and node.parent.test.op == "not"
36 and isinstance(node.parent.test.operand, nodes.Name)
37 and node.parent.test.operand.name == node.name
38 ):
39 return
40
41 # Exempt "if <func> is not None" cases
42 # pylint: disable=too-many-boolean-expressions
43 if (
44 isinstance(node.parent.test, nodes.Compare)
45 and isinstance(node.parent.test.left, nodes.Name)
46 and node.parent.test.left.name == node.name
47 and node.parent.test.ops[0][0] == "is"
48 and isinstance(node.parent.test.ops[0][1], nodes.Const)
49 and node.parent.test.ops[0][1].value is None
50 ):
51 return
52
53 # Check if we have forward references for this node.
54 try:
55 redefinition_index = redefinitions.index(node)
56 except ValueError:
57 pass
58 else:
59 for redefinition in redefinitions[:redefinition_index]:
60 inferred = utils.safe_infer(redefinition)
61 if (
62 inferred
63 and isinstance(inferred, astroid.Instance)
64 and inferred.qname() == TYPING_FORWARD_REF_QNAME
65 ):
66 return
67
68 dummy_variables_rgx = self.linter.config.dummy_variables_rgx
69 if dummy_variables_rgx and dummy_variables_rgx.match(node.name):
70 return
71 self.add_message(
72 "function-redefined",
73 node=node,
74 args=(redeftype, defined_self.fromlineno),
75 )
Path 5: 10 calls (0.0)
'function' (10)
FunctionDef (10)
None (10)
GeneratorExit (10)
1def _check_redefinition(
2 self, redeftype: str, node: nodes.Call | nodes.FunctionDef
3 ) -> None:
4 """Check for redefinition of a function / method / class name."""
5 parent_frame = node.parent.frame(future=True)
6
7 # Ignore function stubs created for type information
8 redefinitions = [
9 i
10 for i in parent_frame.locals[node.name]
11 if not (isinstance(i.parent, nodes.AnnAssign) and i.parent.simple)
12 ]
13 defined_self = next(
14 (local for local in redefinitions if not utils.is_overload_stub(local)),
15 node,
16 )
17 if defined_self is not node and not astroid.are_exclusive(node, defined_self):
18 # Additional checks for methods which are not considered
19 # redefined, since they are already part of the base API.
20 if (
21 isinstance(parent_frame, nodes.ClassDef)
22 and node.name in REDEFINABLE_METHODS
23 ):
24 return
25
26 # Skip typing.overload() functions.
27 if utils.is_overload_stub(node):
28 return
29
30 # Exempt functions redefined on a condition.
31 if isinstance(node.parent, nodes.If):
32 # Exempt "if not <func>" cases
33 if (
34 isinstance(node.parent.test, nodes.UnaryOp)
35 and node.parent.test.op == "not"
36 and isinstance(node.parent.test.operand, nodes.Name)
37 and node.parent.test.operand.name == node.name
38 ):
39 return
40
41 # Exempt "if <func> is not None" cases
42 # pylint: disable=too-many-boolean-expressions
43 if (
44 isinstance(node.parent.test, nodes.Compare)
45 and isinstance(node.parent.test.left, nodes.Name)
46 and node.parent.test.left.name == node.name
47 and node.parent.test.ops[0][0] == "is"
48 and isinstance(node.parent.test.ops[0][1], nodes.Const)
49 and node.parent.test.ops[0][1].value is None
50 ):
51 return
52
53 # Check if we have forward references for this node.
54 try:
55 redefinition_index = redefinitions.index(node)
56 except ValueError:
57 pass
58 else:
59 for redefinition in redefinitions[:redefinition_index]:
60 inferred = utils.safe_infer(redefinition)
61 if (
62 inferred
63 and isinstance(inferred, astroid.Instance)
64 and inferred.qname() == TYPING_FORWARD_REF_QNAME
65 ):
66 return
67
68 dummy_variables_rgx = self.linter.config.dummy_variables_rgx
69 if dummy_variables_rgx and dummy_variables_rgx.match(node.name):
70 return
71 self.add_message(
72 "function-redefined",
73 node=node,
74 args=(redeftype, defined_self.fromlineno),
75 )
Path 6: 2 calls (0.0)
'function' (2)
FunctionDef (2)
GeneratorExit (2)
1def _check_redefinition(
2 self, redeftype: str, node: nodes.Call | nodes.FunctionDef
3 ) -> None:
4 """Check for redefinition of a function / method / class name."""
5 parent_frame = node.parent.frame(future=True)
6
7 # Ignore function stubs created for type information
8 redefinitions = [
9 i
10 for i in parent_frame.locals[node.name]
11 if not (isinstance(i.parent, nodes.AnnAssign) and i.parent.simple)
12 ]
13 defined_self = next(
14 (local for local in redefinitions if not utils.is_overload_stub(local)),
15 node,
16 )
17 if defined_self is not node and not astroid.are_exclusive(node, defined_self):
18 # Additional checks for methods which are not considered
19 # redefined, since they are already part of the base API.
20 if (
21 isinstance(parent_frame, nodes.ClassDef)
22 and node.name in REDEFINABLE_METHODS
23 ):
24 return
25
26 # Skip typing.overload() functions.
27 if utils.is_overload_stub(node):
28 return
29
30 # Exempt functions redefined on a condition.
31 if isinstance(node.parent, nodes.If):
32 # Exempt "if not <func>" cases
33 if (
34 isinstance(node.parent.test, nodes.UnaryOp)
35 and node.parent.test.op == "not"
36 and isinstance(node.parent.test.operand, nodes.Name)
37 and node.parent.test.operand.name == node.name
38 ):
39 return
40
41 # Exempt "if <func> is not None" cases
42 # pylint: disable=too-many-boolean-expressions
43 if (
44 isinstance(node.parent.test, nodes.Compare)
45 and isinstance(node.parent.test.left, nodes.Name)
46 and node.parent.test.left.name == node.name
47 and node.parent.test.ops[0][0] == "is"
48 and isinstance(node.parent.test.ops[0][1], nodes.Const)
49 and node.parent.test.ops[0][1].value is None
50 ):
51 return
52
53 # Check if we have forward references for this node.
54 try:
55 redefinition_index = redefinitions.index(node)
56 except ValueError:
57 pass
58 else:
59 for redefinition in redefinitions[:redefinition_index]:
60 inferred = utils.safe_infer(redefinition)
61 if (
62 inferred
63 and isinstance(inferred, astroid.Instance)
64 and inferred.qname() == TYPING_FORWARD_REF_QNAME
65 ):
66 return
67
68 dummy_variables_rgx = self.linter.config.dummy_variables_rgx
69 if dummy_variables_rgx and dummy_variables_rgx.match(node.name):
70 return
71 self.add_message(
72 "function-redefined",
73 node=node,
74 args=(redeftype, defined_self.fromlineno),
75 )
Path 7: 2 calls (0.0)
'method' (2)
FunctionDef (2)
None (2)
GeneratorExit (2)
1def _check_redefinition(
2 self, redeftype: str, node: nodes.Call | nodes.FunctionDef
3 ) -> None:
4 """Check for redefinition of a function / method / class name."""
5 parent_frame = node.parent.frame(future=True)
6
7 # Ignore function stubs created for type information
8 redefinitions = [
9 i
10 for i in parent_frame.locals[node.name]
11 if not (isinstance(i.parent, nodes.AnnAssign) and i.parent.simple)
12 ]
13 defined_self = next(
14 (local for local in redefinitions if not utils.is_overload_stub(local)),
15 node,
16 )
17 if defined_self is not node and not astroid.are_exclusive(node, defined_self):
18 # Additional checks for methods which are not considered
19 # redefined, since they are already part of the base API.
20 if (
21 isinstance(parent_frame, nodes.ClassDef)
22 and node.name in REDEFINABLE_METHODS
23 ):
24 return
25
26 # Skip typing.overload() functions.
27 if utils.is_overload_stub(node):
28 return
29
30 # Exempt functions redefined on a condition.
31 if isinstance(node.parent, nodes.If):
32 # Exempt "if not <func>" cases
33 if (
34 isinstance(node.parent.test, nodes.UnaryOp)
35 and node.parent.test.op == "not"
36 and isinstance(node.parent.test.operand, nodes.Name)
37 and node.parent.test.operand.name == node.name
38 ):
39 return
40
41 # Exempt "if <func> is not None" cases
42 # pylint: disable=too-many-boolean-expressions
43 if (
44 isinstance(node.parent.test, nodes.Compare)
45 and isinstance(node.parent.test.left, nodes.Name)
46 and node.parent.test.left.name == node.name
47 and node.parent.test.ops[0][0] == "is"
48 and isinstance(node.parent.test.ops[0][1], nodes.Const)
49 and node.parent.test.ops[0][1].value is None
50 ):
51 return
52
53 # Check if we have forward references for this node.
54 try:
55 redefinition_index = redefinitions.index(node)
56 except ValueError:
57 pass
58 else:
59 for redefinition in redefinitions[:redefinition_index]:
60 inferred = utils.safe_infer(redefinition)
61 if (
62 inferred
63 and isinstance(inferred, astroid.Instance)
64 and inferred.qname() == TYPING_FORWARD_REF_QNAME
65 ):
66 return
67
68 dummy_variables_rgx = self.linter.config.dummy_variables_rgx
69 if dummy_variables_rgx and dummy_variables_rgx.match(node.name):
70 return
71 self.add_message(
72 "function-redefined",
73 node=node,
74 args=(redeftype, defined_self.fromlineno),
75 )
Path 8: 1 calls (0.0)
'function' (1)
FunctionDef (1)
None (1)
GeneratorExit (1)
1def _check_redefinition(
2 self, redeftype: str, node: nodes.Call | nodes.FunctionDef
3 ) -> None:
4 """Check for redefinition of a function / method / class name."""
5 parent_frame = node.parent.frame(future=True)
6
7 # Ignore function stubs created for type information
8 redefinitions = [
9 i
10 for i in parent_frame.locals[node.name]
11 if not (isinstance(i.parent, nodes.AnnAssign) and i.parent.simple)
12 ]
13 defined_self = next(
14 (local for local in redefinitions if not utils.is_overload_stub(local)),
15 node,
16 )
17 if defined_self is not node and not astroid.are_exclusive(node, defined_self):
18 # Additional checks for methods which are not considered
19 # redefined, since they are already part of the base API.
20 if (
21 isinstance(parent_frame, nodes.ClassDef)
22 and node.name in REDEFINABLE_METHODS
23 ):
24 return
25
26 # Skip typing.overload() functions.
27 if utils.is_overload_stub(node):
28 return
29
30 # Exempt functions redefined on a condition.
31 if isinstance(node.parent, nodes.If):
32 # Exempt "if not <func>" cases
33 if (
34 isinstance(node.parent.test, nodes.UnaryOp)
35 and node.parent.test.op == "not"
36 and isinstance(node.parent.test.operand, nodes.Name)
37 and node.parent.test.operand.name == node.name
38 ):
39 return
40
41 # Exempt "if <func> is not None" cases
42 # pylint: disable=too-many-boolean-expressions
43 if (
44 isinstance(node.parent.test, nodes.Compare)
45 and isinstance(node.parent.test.left, nodes.Name)
46 and node.parent.test.left.name == node.name
47 and node.parent.test.ops[0][0] == "is"
48 and isinstance(node.parent.test.ops[0][1], nodes.Const)
49 and node.parent.test.ops[0][1].value is None
50 ):
51 return
52
53 # Check if we have forward references for this node.
54 try:
55 redefinition_index = redefinitions.index(node)
56 except ValueError:
57 pass
58 else:
59 for redefinition in redefinitions[:redefinition_index]:
60 inferred = utils.safe_infer(redefinition)
61 if (
62 inferred
63 and isinstance(inferred, astroid.Instance)
64 and inferred.qname() == TYPING_FORWARD_REF_QNAME
65 ):
66 return
67
68 dummy_variables_rgx = self.linter.config.dummy_variables_rgx
69 if dummy_variables_rgx and dummy_variables_rgx.match(node.name):
70 return
71 self.add_message(
72 "function-redefined",
73 node=node,
74 args=(redeftype, defined_self.fromlineno),
75 )
Path 9: 1 calls (0.0)
'function' (1)
FunctionDef (1)
None (1)
GeneratorExit (1)
1def _check_redefinition(
2 self, redeftype: str, node: nodes.Call | nodes.FunctionDef
3 ) -> None:
4 """Check for redefinition of a function / method / class name."""
5 parent_frame = node.parent.frame(future=True)
6
7 # Ignore function stubs created for type information
8 redefinitions = [
9 i
10 for i in parent_frame.locals[node.name]
11 if not (isinstance(i.parent, nodes.AnnAssign) and i.parent.simple)
12 ]
13 defined_self = next(
14 (local for local in redefinitions if not utils.is_overload_stub(local)),
15 node,
16 )
17 if defined_self is not node and not astroid.are_exclusive(node, defined_self):
18 # Additional checks for methods which are not considered
19 # redefined, since they are already part of the base API.
20 if (
21 isinstance(parent_frame, nodes.ClassDef)
22 and node.name in REDEFINABLE_METHODS
23 ):
24 return
25
26 # Skip typing.overload() functions.
27 if utils.is_overload_stub(node):
28 return
29
30 # Exempt functions redefined on a condition.
31 if isinstance(node.parent, nodes.If):
32 # Exempt "if not <func>" cases
33 if (
34 isinstance(node.parent.test, nodes.UnaryOp)
35 and node.parent.test.op == "not"
36 and isinstance(node.parent.test.operand, nodes.Name)
37 and node.parent.test.operand.name == node.name
38 ):
39 return
40
41 # Exempt "if <func> is not None" cases
42 # pylint: disable=too-many-boolean-expressions
43 if (
44 isinstance(node.parent.test, nodes.Compare)
45 and isinstance(node.parent.test.left, nodes.Name)
46 and node.parent.test.left.name == node.name
47 and node.parent.test.ops[0][0] == "is"
48 and isinstance(node.parent.test.ops[0][1], nodes.Const)
49 and node.parent.test.ops[0][1].value is None
50 ):
51 return
52
53 # Check if we have forward references for this node.
54 try:
55 redefinition_index = redefinitions.index(node)
56 except ValueError:
57 pass
58 else:
59 for redefinition in redefinitions[:redefinition_index]:
60 inferred = utils.safe_infer(redefinition)
61 if (
62 inferred
63 and isinstance(inferred, astroid.Instance)
64 and inferred.qname() == TYPING_FORWARD_REF_QNAME
65 ):
66 return
67
68 dummy_variables_rgx = self.linter.config.dummy_variables_rgx
69 if dummy_variables_rgx and dummy_variables_rgx.match(node.name):
70 return
71 self.add_message(
72 "function-redefined",
73 node=node,
74 args=(redeftype, defined_self.fromlineno),
75 )
Path 10: 1 calls (0.0)
'method' (1)
FunctionDef (1)
None (1)
GeneratorExit (1)
1def _check_redefinition(
2 self, redeftype: str, node: nodes.Call | nodes.FunctionDef
3 ) -> None:
4 """Check for redefinition of a function / method / class name."""
5 parent_frame = node.parent.frame(future=True)
6
7 # Ignore function stubs created for type information
8 redefinitions = [
9 i
10 for i in parent_frame.locals[node.name]
11 if not (isinstance(i.parent, nodes.AnnAssign) and i.parent.simple)
12 ]
13 defined_self = next(
14 (local for local in redefinitions if not utils.is_overload_stub(local)),
15 node,
16 )
17 if defined_self is not node and not astroid.are_exclusive(node, defined_self):
18 # Additional checks for methods which are not considered
19 # redefined, since they are already part of the base API.
20 if (
21 isinstance(parent_frame, nodes.ClassDef)
22 and node.name in REDEFINABLE_METHODS
23 ):
24 return
25
26 # Skip typing.overload() functions.
27 if utils.is_overload_stub(node):
28 return
29
30 # Exempt functions redefined on a condition.
31 if isinstance(node.parent, nodes.If):
32 # Exempt "if not <func>" cases
33 if (
34 isinstance(node.parent.test, nodes.UnaryOp)
35 and node.parent.test.op == "not"
36 and isinstance(node.parent.test.operand, nodes.Name)
37 and node.parent.test.operand.name == node.name
38 ):
39 return
40
41 # Exempt "if <func> is not None" cases
42 # pylint: disable=too-many-boolean-expressions
43 if (
44 isinstance(node.parent.test, nodes.Compare)
45 and isinstance(node.parent.test.left, nodes.Name)
46 and node.parent.test.left.name == node.name
47 and node.parent.test.ops[0][0] == "is"
48 and isinstance(node.parent.test.ops[0][1], nodes.Const)
49 and node.parent.test.ops[0][1].value is None
50 ):
51 return
52
53 # Check if we have forward references for this node.
54 try:
55 redefinition_index = redefinitions.index(node)
56 except ValueError:
57 pass
58 else:
59 for redefinition in redefinitions[:redefinition_index]:
60 inferred = utils.safe_infer(redefinition)
61 if (
62 inferred
63 and isinstance(inferred, astroid.Instance)
64 and inferred.qname() == TYPING_FORWARD_REF_QNAME
65 ):
66 return
67
68 dummy_variables_rgx = self.linter.config.dummy_variables_rgx
69 if dummy_variables_rgx and dummy_variables_rgx.match(node.name):
70 return
71 self.add_message(
72 "function-redefined",
73 node=node,
74 args=(redeftype, defined_self.fromlineno),
75 )
Path 11: 1 calls (0.0)
'function' (1)
FunctionDef (1)
None (1)
GeneratorExit (1)
1def _check_redefinition(
2 self, redeftype: str, node: nodes.Call | nodes.FunctionDef
3 ) -> None:
4 """Check for redefinition of a function / method / class name."""
5 parent_frame = node.parent.frame(future=True)
6
7 # Ignore function stubs created for type information
8 redefinitions = [
9 i
10 for i in parent_frame.locals[node.name]
11 if not (isinstance(i.parent, nodes.AnnAssign) and i.parent.simple)
12 ]
13 defined_self = next(
14 (local for local in redefinitions if not utils.is_overload_stub(local)),
15 node,
16 )
17 if defined_self is not node and not astroid.are_exclusive(node, defined_self):
18 # Additional checks for methods which are not considered
19 # redefined, since they are already part of the base API.
20 if (
21 isinstance(parent_frame, nodes.ClassDef)
22 and node.name in REDEFINABLE_METHODS
23 ):
24 return
25
26 # Skip typing.overload() functions.
27 if utils.is_overload_stub(node):
28 return
29
30 # Exempt functions redefined on a condition.
31 if isinstance(node.parent, nodes.If):
32 # Exempt "if not <func>" cases
33 if (
34 isinstance(node.parent.test, nodes.UnaryOp)
35 and node.parent.test.op == "not"
36 and isinstance(node.parent.test.operand, nodes.Name)
37 and node.parent.test.operand.name == node.name
38 ):
39 return
40
41 # Exempt "if <func> is not None" cases
42 # pylint: disable=too-many-boolean-expressions
43 if (
44 isinstance(node.parent.test, nodes.Compare)
45 and isinstance(node.parent.test.left, nodes.Name)
46 and node.parent.test.left.name == node.name
47 and node.parent.test.ops[0][0] == "is"
48 and isinstance(node.parent.test.ops[0][1], nodes.Const)
49 and node.parent.test.ops[0][1].value is None
50 ):
51 return
52
53 # Check if we have forward references for this node.
54 try:
55 redefinition_index = redefinitions.index(node)
56 except ValueError:
57 pass
58 else:
59 for redefinition in redefinitions[:redefinition_index]:
60 inferred = utils.safe_infer(redefinition)
61 if (
62 inferred
63 and isinstance(inferred, astroid.Instance)
64 and inferred.qname() == TYPING_FORWARD_REF_QNAME
65 ):
66 return
67
68 dummy_variables_rgx = self.linter.config.dummy_variables_rgx
69 if dummy_variables_rgx and dummy_variables_rgx.match(node.name):
70 return
71 self.add_message(
72 "function-redefined",
73 node=node,
74 args=(redeftype, defined_self.fromlineno),
75 )
Path 12: 1 calls (0.0)
'function' (1)
FunctionDef (1)
None (1)
GeneratorExit (1)
1def _check_redefinition(
2 self, redeftype: str, node: nodes.Call | nodes.FunctionDef
3 ) -> None:
4 """Check for redefinition of a function / method / class name."""
5 parent_frame = node.parent.frame(future=True)
6
7 # Ignore function stubs created for type information
8 redefinitions = [
9 i
10 for i in parent_frame.locals[node.name]
11 if not (isinstance(i.parent, nodes.AnnAssign) and i.parent.simple)
12 ]
13 defined_self = next(
14 (local for local in redefinitions if not utils.is_overload_stub(local)),
15 node,
16 )
17 if defined_self is not node and not astroid.are_exclusive(node, defined_self):
18 # Additional checks for methods which are not considered
19 # redefined, since they are already part of the base API.
20 if (
21 isinstance(parent_frame, nodes.ClassDef)
22 and node.name in REDEFINABLE_METHODS
23 ):
24 return
25
26 # Skip typing.overload() functions.
27 if utils.is_overload_stub(node):
28 return
29
30 # Exempt functions redefined on a condition.
31 if isinstance(node.parent, nodes.If):
32 # Exempt "if not <func>" cases
33 if (
34 isinstance(node.parent.test, nodes.UnaryOp)
35 and node.parent.test.op == "not"
36 and isinstance(node.parent.test.operand, nodes.Name)
37 and node.parent.test.operand.name == node.name
38 ):
39 return
40
41 # Exempt "if <func> is not None" cases
42 # pylint: disable=too-many-boolean-expressions
43 if (
44 isinstance(node.parent.test, nodes.Compare)
45 and isinstance(node.parent.test.left, nodes.Name)
46 and node.parent.test.left.name == node.name
47 and node.parent.test.ops[0][0] == "is"
48 and isinstance(node.parent.test.ops[0][1], nodes.Const)
49 and node.parent.test.ops[0][1].value is None
50 ):
51 return
52
53 # Check if we have forward references for this node.
54 try:
55 redefinition_index = redefinitions.index(node)
56 except ValueError:
57 pass
58 else:
59 for redefinition in redefinitions[:redefinition_index]:
60 inferred = utils.safe_infer(redefinition)
61 if (
62 inferred
63 and isinstance(inferred, astroid.Instance)
64 and inferred.qname() == TYPING_FORWARD_REF_QNAME
65 ):
66 return
67
68 dummy_variables_rgx = self.linter.config.dummy_variables_rgx
69 if dummy_variables_rgx and dummy_variables_rgx.match(node.name):
70 return
71 self.add_message(
72 "function-redefined",
73 node=node,
74 args=(redeftype, defined_self.fromlineno),
75 )
Path 13: 1 calls (0.0)
'class' (1)
ClassDef (1)
None (1)
GeneratorExit (1)
1def _check_redefinition(
2 self, redeftype: str, node: nodes.Call | nodes.FunctionDef
3 ) -> None:
4 """Check for redefinition of a function / method / class name."""
5 parent_frame = node.parent.frame(future=True)
6
7 # Ignore function stubs created for type information
8 redefinitions = [
9 i
10 for i in parent_frame.locals[node.name]
11 if not (isinstance(i.parent, nodes.AnnAssign) and i.parent.simple)
12 ]
13 defined_self = next(
14 (local for local in redefinitions if not utils.is_overload_stub(local)),
15 node,
16 )
17 if defined_self is not node and not astroid.are_exclusive(node, defined_self):
18 # Additional checks for methods which are not considered
19 # redefined, since they are already part of the base API.
20 if (
21 isinstance(parent_frame, nodes.ClassDef)
22 and node.name in REDEFINABLE_METHODS
23 ):
24 return
25
26 # Skip typing.overload() functions.
27 if utils.is_overload_stub(node):
28 return
29
30 # Exempt functions redefined on a condition.
31 if isinstance(node.parent, nodes.If):
32 # Exempt "if not <func>" cases
33 if (
34 isinstance(node.parent.test, nodes.UnaryOp)
35 and node.parent.test.op == "not"
36 and isinstance(node.parent.test.operand, nodes.Name)
37 and node.parent.test.operand.name == node.name
38 ):
39 return
40
41 # Exempt "if <func> is not None" cases
42 # pylint: disable=too-many-boolean-expressions
43 if (
44 isinstance(node.parent.test, nodes.Compare)
45 and isinstance(node.parent.test.left, nodes.Name)
46 and node.parent.test.left.name == node.name
47 and node.parent.test.ops[0][0] == "is"
48 and isinstance(node.parent.test.ops[0][1], nodes.Const)
49 and node.parent.test.ops[0][1].value is None
50 ):
51 return
52
53 # Check if we have forward references for this node.
54 try:
55 redefinition_index = redefinitions.index(node)
56 except ValueError:
57 pass
58 else:
59 for redefinition in redefinitions[:redefinition_index]:
60 inferred = utils.safe_infer(redefinition)
61 if (
62 inferred
63 and isinstance(inferred, astroid.Instance)
64 and inferred.qname() == TYPING_FORWARD_REF_QNAME
65 ):
66 return
67
68 dummy_variables_rgx = self.linter.config.dummy_variables_rgx
69 if dummy_variables_rgx and dummy_variables_rgx.match(node.name):
70 return
71 self.add_message(
72 "function-redefined",
73 node=node,
74 args=(redeftype, defined_self.fromlineno),
75 )