Method: pylint.checkers.utils._supports_protocol_method
Calls: 2169, Exceptions: 149, Paths: 5Back
Path 1: 2003 calls (0.92)
ClassDef (487) Dict (447) Instance (422) List (388) Tuple (163) Const (54) Set (27) FrozenSet (5) Generator (5) AsyncGenerator (5)
'__iter__' (789) '__class_getitem__' (479) '__getitem__' (408) '__contains__' (118) 'keys' (117) '__setitem__' (67) '__delitem__' (18) '__aiter__' (7)...
True (2003)
1def _supports_protocol_method(value: nodes.NodeNG, attr: str) -> bool:
2 try:
3 attributes = value.getattr(attr)
4 except astroid.NotFoundError:
5 return False
6
7 first = attributes[0]
8
9 # Return False if a constant is assigned
10 if isinstance(first, nodes.AssignName):
11 this_assign_parent = get_node_first_ancestor_of_type(
12 first, (nodes.Assign, nodes.NamedExpr)
13 )
14 if this_assign_parent is None: # pragma: no cover
15 # Cannot imagine this being None, but return True to avoid false positives
16 return True
17 if isinstance(this_assign_parent.value, nodes.BaseContainer):
18 if all(isinstance(n, nodes.Const) for n in this_assign_parent.value.elts):
19 return False
20 if isinstance(this_assign_parent.value, nodes.Const):
21 return False
22 return True
Path 2: 149 calls (0.07)
Instance (62) Const (44) ClassDef (42) Generator (1)
'__getitem__' (62) '__iter__' (42) '__class_getitem__' (22) '__contains__' (19) '__setitem__' (3) '__delitem__' (1)
False (149)
AttributeInferenceError (149)
1def _supports_protocol_method(value: nodes.NodeNG, attr: str) -> bool:
2 try:
3 attributes = value.getattr(attr)
4 except astroid.NotFoundError:
5 return False
6
7 first = attributes[0]
8
9 # Return False if a constant is assigned
10 if isinstance(first, nodes.AssignName):
11 this_assign_parent = get_node_first_ancestor_of_type(
12 first, (nodes.Assign, nodes.NamedExpr)
13 )
14 if this_assign_parent is None: # pragma: no cover
15 # Cannot imagine this being None, but return True to avoid false positives
16 return True
17 if isinstance(this_assign_parent.value, nodes.BaseContainer):
18 if all(isinstance(n, nodes.Const) for n in this_assign_parent.value.elts):
19 return False
20 if isinstance(this_assign_parent.value, nodes.Const):
21 return False
22 return True
Path 3: 10 calls (0.0)
ClassDef (8) Instance (2)
'__class_getitem__' (8) '__iter__' (2)
True (10)
1def _supports_protocol_method(value: nodes.NodeNG, attr: str) -> bool:
2 try:
3 attributes = value.getattr(attr)
4 except astroid.NotFoundError:
5 return False
6
7 first = attributes[0]
8
9 # Return False if a constant is assigned
10 if isinstance(first, nodes.AssignName):
11 this_assign_parent = get_node_first_ancestor_of_type(
12 first, (nodes.Assign, nodes.NamedExpr)
13 )
14 if this_assign_parent is None: # pragma: no cover
15 # Cannot imagine this being None, but return True to avoid false positives
16 return True
17 if isinstance(this_assign_parent.value, nodes.BaseContainer):
18 if all(isinstance(n, nodes.Const) for n in this_assign_parent.value.elts):
19 return False
20 if isinstance(this_assign_parent.value, nodes.Const):
21 return False
22 return True
Path 4: 6 calls (0.0)
ClassDef (3) Instance (3)
'__contains__' (3) '__getitem__' (2) '__iter__' (1)
False (6)
1def _supports_protocol_method(value: nodes.NodeNG, attr: str) -> bool:
2 try:
3 attributes = value.getattr(attr)
4 except astroid.NotFoundError:
5 return False
6
7 first = attributes[0]
8
9 # Return False if a constant is assigned
10 if isinstance(first, nodes.AssignName):
11 this_assign_parent = get_node_first_ancestor_of_type(
12 first, (nodes.Assign, nodes.NamedExpr)
13 )
14 if this_assign_parent is None: # pragma: no cover
15 # Cannot imagine this being None, but return True to avoid false positives
16 return True
17 if isinstance(this_assign_parent.value, nodes.BaseContainer):
18 if all(isinstance(n, nodes.Const) for n in this_assign_parent.value.elts):
19 return False
20 if isinstance(this_assign_parent.value, nodes.Const):
21 return False
22 return True
Path 5: 1 calls (0.0)
Instance (1)
'__iter__' (1)
False (1)
1def _supports_protocol_method(value: nodes.NodeNG, attr: str) -> bool:
2 try:
3 attributes = value.getattr(attr)
4 except astroid.NotFoundError:
5 return False
6
7 first = attributes[0]
8
9 # Return False if a constant is assigned
10 if isinstance(first, nodes.AssignName):
11 this_assign_parent = get_node_first_ancestor_of_type(
12 first, (nodes.Assign, nodes.NamedExpr)
13 )
14 if this_assign_parent is None: # pragma: no cover
15 # Cannot imagine this being None, but return True to avoid false positives
16 return True
17 if isinstance(this_assign_parent.value, nodes.BaseContainer):
18 if all(isinstance(n, nodes.Const) for n in this_assign_parent.value.elts):
19 return False
20 if isinstance(this_assign_parent.value, nodes.Const):
21 return False
22 return True