fname
stringlengths
63
176
rel_fname
stringclasses
706 values
line
int64
-1
4.5k
name
stringlengths
1
81
kind
stringclasses
2 values
category
stringclasses
2 values
info
stringlengths
0
77.9k
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/overlapping_exceptions.py
pylint/extensions/overlapping_exceptions.py
61
ancestors
ref
function
anc for anc in exc.ancestors() if isinstance(anc, astroid.ClassDef)
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/overlapping_exceptions.py
pylint/extensions/overlapping_exceptions.py
67
ancestors
ref
function
for anc in prev_exc.ancestors()
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/overlapping_exceptions.py
pylint/extensions/overlapping_exceptions.py
71
add_message
ref
function
self.add_message(
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/overlapping_exceptions.py
pylint/extensions/overlapping_exceptions.py
74
as_string
ref
function
args=f"{prev_part.as_string()} and {part.as_string()} are the same",
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/overlapping_exceptions.py
pylint/extensions/overlapping_exceptions.py
74
as_string
ref
function
args=f"{prev_part.as_string()} and {part.as_string()} are the same",
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/overlapping_exceptions.py
pylint/extensions/overlapping_exceptions.py
79
add_message
ref
function
self.add_message(
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/overlapping_exceptions.py
pylint/extensions/overlapping_exceptions.py
82
as_string
ref
class
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/overlapping_exceptions.py
pylint/extensions/overlapping_exceptions.py
82
as_string
ref
class
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/overlapping_exceptions.py
pylint/extensions/overlapping_exceptions.py
87
register
def
function
def register(linter: "PyLinter") -> None: linter.register_checker(OverlappingExceptionsChecker(linter))
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/overlapping_exceptions.py
pylint/extensions/overlapping_exceptions.py
88
register_checker
ref
function
linter.register_checker(OverlappingExceptionsChecker(linter))
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/overlapping_exceptions.py
pylint/extensions/overlapping_exceptions.py
88
OverlappingExceptionsChecker
ref
function
linter.register_checker(OverlappingExceptionsChecker(linter))
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/redefined_variable_type.py
pylint/extensions/redefined_variable_type.py
25
MultipleTypesChecker
def
class
visit_classdef leave_classdef visit_module _check_and_add_messages visit_assign
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/redefined_variable_type.py
pylint/extensions/redefined_variable_type.py
51
visit_classdef
def
class
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/redefined_variable_type.py
pylint/extensions/redefined_variable_type.py
54
check_messages
ref
function
@check_messages("redefined-variable-type")
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/redefined_variable_type.py
pylint/extensions/redefined_variable_type.py
55
leave_classdef
def
class
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/redefined_variable_type.py
pylint/extensions/redefined_variable_type.py
56
_check_and_add_messages
ref
function
self._check_and_add_messages()
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/redefined_variable_type.py
pylint/extensions/redefined_variable_type.py
61
visit_module
def
function
def visit_module(self, _: nodes.Module) -> None: self._assigns: List[dict] = [{}] def _check_and_add_messages(self): assigns = self._assigns.pop() for name, args in assigns.items(): if len(args) <= 1: continue orig_node, orig_type = args[0] # Check if there is a type in the following nodes that would be # different from orig_type. for redef_node, redef_type in args[1:]: if redef_type == orig_type: continue # if a variable is defined to several types in an if node, # this is not actually redefining. orig_parent = orig_node.parent redef_parent = redef_node.parent if isinstance(orig_parent, nodes.If): if orig_parent == redef_parent: if ( redef_node in orig_parent.orelse and orig_node not in orig_parent.orelse ): orig_node, orig_type = redef_node, redef_type continue elif isinstance( redef_parent, nodes.If ) and redef_parent in orig_parent.nodes_of_class(nodes.If): orig_node, orig_type = redef_node, redef_type continue orig_type = orig_type.replace("builtins.", "") redef_type = redef_type.replace("builtins.", "") self.add_message( "redefined-variable-type", node=redef_node, args=(name, orig_type, redef_type), ) break def visit_assign(self, node: nodes.Assign) -> None: # we don't handle multiple assignment nor slice assignment target = node.targets[0] if isinstance(target, (nodes.Tuple, nodes.Subscript)): return # ignore NoneType if is_none(node): return _type = node_type(node.value) if _type: self._assigns[-1].setdefault(target.as_string(), []).append( (node, _type.pytype()) )
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/redefined_variable_type.py
pylint/extensions/redefined_variable_type.py
64
_check_and_add_messages
def
function
def _check_and_add_messages(self): assigns = self._assigns.pop() for name, args in assigns.items(): if len(args) <= 1: continue orig_node, orig_type = args[0] # Check if there is a type in the following nodes that would be # different from orig_type. for redef_node, redef_type in args[1:]: if redef_type == orig_type: continue # if a variable is defined to several types in an if node, # this is not actually redefining. orig_parent = orig_node.parent redef_parent = redef_node.parent if isinstance(orig_parent, nodes.If): if orig_parent == redef_parent: if ( redef_node in orig_parent.orelse and orig_node not in orig_parent.orelse ): orig_node, orig_type = redef_node, redef_type continue elif isinstance( redef_parent, nodes.If ) and redef_parent in orig_parent.nodes_of_class(nodes.If): orig_node, orig_type = redef_node, redef_type continue orig_type = orig_type.replace("builtins.", "") redef_type = redef_type.replace("builtins.", "") self.add_message( "redefined-variable-type", node=redef_node, args=(name, orig_type, redef_type), ) break def visit_assign(self, node: nodes.Assign) -> None: # we don't handle multiple assignment nor slice assignment target = node.targets[0] if isinstance(target, (nodes.Tuple, nodes.Subscript)): return # ignore NoneType if is_none(node): return _type = node_type(node.value) if _type: self._assigns[-1].setdefault(target.as_string(), []).append( (node, _type.pytype()) )
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/redefined_variable_type.py
pylint/extensions/redefined_variable_type.py
89
nodes_of_class
ref
class
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/redefined_variable_type.py
pylint/extensions/redefined_variable_type.py
94
add_message
ref
function
self.add_message(
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/redefined_variable_type.py
pylint/extensions/redefined_variable_type.py
101
visit_assign
def
function
def visit_assign(self, node: nodes.Assign) -> None: # we don't handle multiple assignment nor slice assignment target = node.targets[0] if isinstance(target, (nodes.Tuple, nodes.Subscript)): return # ignore NoneType if is_none(node): return _type = node_type(node.value) if _type: self._assigns[-1].setdefault(target.as_string(), []).append( (node, _type.pytype()) )
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/redefined_variable_type.py
pylint/extensions/redefined_variable_type.py
107
is_none
ref
function
if is_none(node):
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/redefined_variable_type.py
pylint/extensions/redefined_variable_type.py
109
node_type
ref
function
_type = node_type(node.value)
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/redefined_variable_type.py
pylint/extensions/redefined_variable_type.py
111
as_string
ref
function
self._assigns[-1].setdefault(target.as_string(), []).append(
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/redefined_variable_type.py
pylint/extensions/redefined_variable_type.py
112
pytype
ref
function
(node, _type.pytype())
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/redefined_variable_type.py
pylint/extensions/redefined_variable_type.py
116
register
def
function
def register(linter: "PyLinter") -> None: linter.register_checker(MultipleTypesChecker(linter))
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/redefined_variable_type.py
pylint/extensions/redefined_variable_type.py
117
register_checker
ref
function
linter.register_checker(MultipleTypesChecker(linter))
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/redefined_variable_type.py
pylint/extensions/redefined_variable_type.py
117
MultipleTypesChecker
ref
function
linter.register_checker(MultipleTypesChecker(linter))
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/set_membership.py
pylint/extensions/set_membership.py
12
SetMembershipChecker
def
class
__init__ visit_compare _check_in_comparison
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/set_membership.py
pylint/extensions/set_membership.py
31
check_messages
ref
function
@check_messages("use-set-for-membership")
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/set_membership.py
pylint/extensions/set_membership.py
32
visit_compare
def
function
def visit_compare(self, node: nodes.Compare) -> None: for op, comparator in node.ops: if op == "in": self._check_in_comparison(comparator) def _check_in_comparison(self, comparator: nodes.NodeNG) -> None: """Checks for membership comparisons with in-place container objects.""" if not isinstance(comparator, nodes.BaseContainer) or isinstance( comparator, nodes.Set ): return # Heuristic - We need to be sure all items in set are hashable if all(isinstance(item, nodes.Const) for item in comparator.elts): self.add_message("use-set-for-membership", node=comparator)
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/set_membership.py
pylint/extensions/set_membership.py
35
_check_in_comparison
ref
function
self._check_in_comparison(comparator)
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/set_membership.py
pylint/extensions/set_membership.py
37
_check_in_comparison
def
function
def _check_in_comparison(self, comparator: nodes.NodeNG) -> None: """Checks for membership comparisons with in-place container objects.""" if not isinstance(comparator, nodes.BaseContainer) or isinstance( comparator, nodes.Set ): return # Heuristic - We need to be sure all items in set are hashable if all(isinstance(item, nodes.Const) for item in comparator.elts): self.add_message("use-set-for-membership", node=comparator)
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/set_membership.py
pylint/extensions/set_membership.py
46
add_message
ref
function
self.add_message("use-set-for-membership", node=comparator)
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/set_membership.py
pylint/extensions/set_membership.py
49
register
def
function
def register(linter: "PyLinter") -> None: linter.register_checker(SetMembershipChecker(linter))
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/set_membership.py
pylint/extensions/set_membership.py
50
register_checker
ref
function
linter.register_checker(SetMembershipChecker(linter))
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/set_membership.py
pylint/extensions/set_membership.py
50
SetMembershipChecker
ref
function
linter.register_checker(SetMembershipChecker(linter))
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/typing.py
pylint/extensions/typing.py
18
TypingAlias
def
class
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/typing.py
pylint/extensions/typing.py
24
TypingAlias
ref
function
"typing.Tuple": TypingAlias("tuple", False),
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/typing.py
pylint/extensions/typing.py
25
TypingAlias
ref
function
"typing.List": TypingAlias("list", False),
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/typing.py
pylint/extensions/typing.py
26
TypingAlias
ref
function
"typing.Dict": TypingAlias("dict", False),
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/typing.py
pylint/extensions/typing.py
27
TypingAlias
ref
function
"typing.Set": TypingAlias("set", False),
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/typing.py
pylint/extensions/typing.py
28
TypingAlias
ref
function
"typing.FrozenSet": TypingAlias("frozenset", False),
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/typing.py
pylint/extensions/typing.py
29
TypingAlias
ref
function
"typing.Type": TypingAlias("type", False),
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/typing.py
pylint/extensions/typing.py
30
TypingAlias
ref
function
"typing.Deque": TypingAlias("collections.deque", True),
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/typing.py
pylint/extensions/typing.py
31
TypingAlias
ref
function
"typing.DefaultDict": TypingAlias("collections.defaultdict", True),
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/typing.py
pylint/extensions/typing.py
32
TypingAlias
ref
function
"typing.OrderedDict": TypingAlias("collections.OrderedDict", True),
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/typing.py
pylint/extensions/typing.py
33
TypingAlias
ref
function
"typing.Counter": TypingAlias("collections.Counter", True),
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/typing.py
pylint/extensions/typing.py
34
TypingAlias
ref
function
"typing.ChainMap": TypingAlias("collections.ChainMap", True),
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/typing.py
pylint/extensions/typing.py
35
TypingAlias
ref
function
"typing.Awaitable": TypingAlias("collections.abc.Awaitable", True),
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/typing.py
pylint/extensions/typing.py
36
TypingAlias
ref
function
"typing.Coroutine": TypingAlias("collections.abc.Coroutine", True),
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/typing.py
pylint/extensions/typing.py
37
TypingAlias
ref
function
"typing.AsyncIterable": TypingAlias("collections.abc.AsyncIterable", True),
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/typing.py
pylint/extensions/typing.py
38
TypingAlias
ref
function
"typing.AsyncIterator": TypingAlias("collections.abc.AsyncIterator", True),
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/typing.py
pylint/extensions/typing.py
39
TypingAlias
ref
function
"typing.AsyncGenerator": TypingAlias("collections.abc.AsyncGenerator", True),
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/typing.py
pylint/extensions/typing.py
40
TypingAlias
ref
function
"typing.Iterable": TypingAlias("collections.abc.Iterable", True),
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/typing.py
pylint/extensions/typing.py
41
TypingAlias
ref
function
"typing.Iterator": TypingAlias("collections.abc.Iterator", True),
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/typing.py
pylint/extensions/typing.py
42
TypingAlias
ref
function
"typing.Generator": TypingAlias("collections.abc.Generator", True),
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/typing.py
pylint/extensions/typing.py
43
TypingAlias
ref
function
"typing.Reversible": TypingAlias("collections.abc.Reversible", True),
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/typing.py
pylint/extensions/typing.py
44
TypingAlias
ref
function
"typing.Container": TypingAlias("collections.abc.Container", True),
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/typing.py
pylint/extensions/typing.py
45
TypingAlias
ref
function
"typing.Collection": TypingAlias("collections.abc.Collection", True),
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/typing.py
pylint/extensions/typing.py
46
TypingAlias
ref
function
"typing.Callable": TypingAlias("collections.abc.Callable", True),
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/typing.py
pylint/extensions/typing.py
47
TypingAlias
ref
function
"typing.AbstractSet": TypingAlias("collections.abc.Set", False),
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/typing.py
pylint/extensions/typing.py
48
TypingAlias
ref
function
"typing.MutableSet": TypingAlias("collections.abc.MutableSet", True),
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/typing.py
pylint/extensions/typing.py
49
TypingAlias
ref
function
"typing.Mapping": TypingAlias("collections.abc.Mapping", True),
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/typing.py
pylint/extensions/typing.py
50
TypingAlias
ref
function
"typing.MutableMapping": TypingAlias("collections.abc.MutableMapping", True),
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/typing.py
pylint/extensions/typing.py
51
TypingAlias
ref
function
"typing.Sequence": TypingAlias("collections.abc.Sequence", True),
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/typing.py
pylint/extensions/typing.py
52
TypingAlias
ref
function
"typing.MutableSequence": TypingAlias("collections.abc.MutableSequence", True),
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/typing.py
pylint/extensions/typing.py
53
TypingAlias
ref
function
"typing.ByteString": TypingAlias("collections.abc.ByteString", True),
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/typing.py
pylint/extensions/typing.py
54
TypingAlias
ref
function
"typing.MappingView": TypingAlias("collections.abc.MappingView", True),
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/typing.py
pylint/extensions/typing.py
55
TypingAlias
ref
function
"typing.KeysView": TypingAlias("collections.abc.KeysView", True),
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/typing.py
pylint/extensions/typing.py
56
TypingAlias
ref
function
"typing.ItemsView": TypingAlias("collections.abc.ItemsView", True),
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/typing.py
pylint/extensions/typing.py
57
TypingAlias
ref
function
"typing.ValuesView": TypingAlias("collections.abc.ValuesView", True),
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/typing.py
pylint/extensions/typing.py
58
TypingAlias
ref
function
"typing.ContextManager": TypingAlias("contextlib.AbstractContextManager", False),
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/typing.py
pylint/extensions/typing.py
59
TypingAlias
ref
function
"typing.AsyncContextManager": TypingAlias(
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/typing.py
pylint/extensions/typing.py
62
TypingAlias
ref
function
"typing.Pattern": TypingAlias("re.Pattern", True),
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/typing.py
pylint/extensions/typing.py
63
TypingAlias
ref
function
"typing.Match": TypingAlias("re.Match", True),
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/typing.py
pylint/extensions/typing.py
64
TypingAlias
ref
function
"typing.Hashable": TypingAlias("collections.abc.Hashable", True),
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/typing.py
pylint/extensions/typing.py
65
TypingAlias
ref
function
"typing.Sized": TypingAlias("collections.abc.Sized", True),
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/typing.py
pylint/extensions/typing.py
72
DeprecatedTypingAliasMsg
def
class
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/typing.py
pylint/extensions/typing.py
79
TypingChecker
def
class
__init__ open _msg_postponed_eval_hint visit_name visit_attribute _check_for_alternative_union_syntax _check_for_typing_alias leave_module
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/typing.py
pylint/extensions/typing.py
143
get_global_option
ref
function
py_version = get_global_option(self, "py-version")
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/typing.py
pylint/extensions/typing.py
155
_msg_postponed_eval_hint
def
function
def _msg_postponed_eval_hint(self, node) -> str: """Message hint if postponed evaluation isn't enabled.""" if self._py310_plus or "annotations" in node.root().future_imports: return "" return ". Add 'from __future__ import annotations' as well" @check_messages( "deprecated-typing-alias", "consider-using-alias", "consider-alternative-union-syntax", ) def visit_name(self, node: nodes.Name) -> None: if self._should_check_typing_alias and node.name in ALIAS_NAMES: self._check_for_typing_alias(node) if self._should_check_alternative_union_syntax and node.name in UNION_NAMES: self._check_for_alternative_union_syntax(node, node.name) @check_messages( "deprecated-typing-alias", "consider-using-alias", "consider-alternative-union-syntax", ) def visit_attribute(self, node: nodes.Attribute) -> None: if self._should_check_typing_alias and node.attrname in ALIAS_NAMES: self._check_for_typing_alias(node) if self._should_check_alternative_union_syntax and node.attrname in UNION_NAMES: self._check_for_alternative_union_syntax(node, node.attrname) def _check_for_alternative_union_syntax( self, node: Union[nodes.Name, nodes.Attribute], name: str, ) -> None: """Check if alternative union syntax could be used. Requires - Python 3.10 - OR: Python 3.7+ with postponed evaluation in a type annotation context """ inferred = safe_infer(node) if not ( isinstance(inferred, nodes.FunctionDef) and inferred.qname() in {"typing.Optional", "typing.Union"} or isinstance(inferred, astroid.bases.Instance) and inferred.qname() == "typing._SpecialForm" ): return if not (self._py310_plus or is_node_in_type_annotation_context(node)): return self.add_message( "consider-alternative-union-syntax", node=node, args=(name, self._msg_postponed_eval_hint(node)), ) def _check_for_typing_alias( self, node: Union[nodes.Name, nodes.Attribute], ) -> None: """Check if typing alias is deprecated or could be replaced. Requires - Python 3.9 - OR: Python 3.7+ with postponed evaluation in a type annotation context For Python 3.7+: Only emit message if change doesn't create any name collisions, only ever used in a type annotation context, and can safely be replaced. """ inferred = safe_infer(node) if not isinstance(inferred, nodes.ClassDef): return alias = DEPRECATED_TYPING_ALIASES.get(inferred.qname(), None) if alias is None: return if self._py39_plus: self.add_message( "deprecated-typing-alias", node=node, args=(inferred.qname(), alias.name), ) return # For PY37+, check for type annotation context first if not is_node_in_type_annotation_context(node) and isinstance( node.parent, nodes.Subscript ): if alias.name_collision is _True: self._alias_name_collisions.add(inferred.qname()) return self._consider_using_alias_msgs.append( DeprecatedTypingAliasMsg( node, inferred.qname(), alias.name, isinstance(node.parent, nodes.Subscript), ) ) @check_messages("consider-using-alias") def leave_module(self, node: nodes.Module) -> None: """After parsing of module is complete, add messages for 'consider-using-alias' check. Make sure results are safe to recommend / collision free. """ if self._py37_plus and not self._py39_plus: msg_future_import = self._msg_postponed_eval_hint(node) for msg in self._consider_using_alias_msgs: if msg.qname in self._alias_name_collisions: continue self.add_message( "consider-using-alias", node=msg.node, args=( msg.qname, msg.alias, msg_future_import if msg.parent_subscript else "", ), ) # Clear all module cache variables self._alias_name_collisions.clear() self._consider_using_alias_msgs.clear()
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/typing.py
pylint/extensions/typing.py
157
root
ref
function
if self._py310_plus or "annotations" in node.root().future_imports:
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/typing.py
pylint/extensions/typing.py
161
check_messages
ref
function
@check_messages(
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/typing.py
pylint/extensions/typing.py
166
visit_name
def
function
def visit_name(self, node: nodes.Name) -> None: if self._should_check_typing_alias and node.name in ALIAS_NAMES: self._check_for_typing_alias(node) if self._should_check_alternative_union_syntax and node.name in UNION_NAMES: self._check_for_alternative_union_syntax(node, node.name) @check_messages( "deprecated-typing-alias", "consider-using-alias", "consider-alternative-union-syntax", ) def visit_attribute(self, node: nodes.Attribute) -> None: if self._should_check_typing_alias and node.attrname in ALIAS_NAMES: self._check_for_typing_alias(node) if self._should_check_alternative_union_syntax and node.attrname in UNION_NAMES: self._check_for_alternative_union_syntax(node, node.attrname) def _check_for_alternative_union_syntax( self, node: Union[nodes.Name, nodes.Attribute], name: str, ) -> None: """Check if alternative union syntax could be used. Requires - Python 3.10 - OR: Python 3.7+ with postponed evaluation in a type annotation context """ inferred = safe_infer(node) if not ( isinstance(inferred, nodes.FunctionDef) and inferred.qname() in {"typing.Optional", "typing.Union"} or isinstance(inferred, astroid.bases.Instance) and inferred.qname() == "typing._SpecialForm" ): return if not (self._py310_plus or is_node_in_type_annotation_context(node)): return self.add_message( "consider-alternative-union-syntax", node=node, args=(name, self._msg_postponed_eval_hint(node)), ) def _check_for_typing_alias( self, node: Union[nodes.Name, nodes.Attribute], ) -> None: """Check if typing alias is deprecated or could be replaced. Requires - Python 3.9 - OR: Python 3.7+ with postponed evaluation in a type annotation context For Python 3.7+: Only emit message if change doesn't create any name collisions, only ever used in a type annotation context, and can safely be replaced. """ inferred = safe_infer(node) if not isinstance(inferred, nodes.ClassDef): return alias = DEPRECATED_TYPING_ALIASES.get(inferred.qname(), None) if alias is None: return if self._py39_plus: self.add_message( "deprecated-typing-alias", node=node, args=(inferred.qname(), alias.name), ) return # For PY37+, check for type annotation context first if not is_node_in_type_annotation_context(node) and isinstance( node.parent, nodes.Subscript ): if alias.name_collision is _True: self._alias_name_collisions.add(inferred.qname()) return self._consider_using_alias_msgs.append( DeprecatedTypingAliasMsg( node, inferred.qname(), alias.name, isinstance(node.parent, nodes.Subscript), ) ) @check_messages("consider-using-alias") def leave_module(self, node: nodes.Module) -> None: """After parsing of module is complete, add messages for 'consider-using-alias' check. Make sure results are safe to recommend / collision free. """ if self._py37_plus and not self._py39_plus: msg_future_import = self._msg_postponed_eval_hint(node) for msg in self._consider_using_alias_msgs: if msg.qname in self._alias_name_collisions: continue self.add_message( "consider-using-alias", node=msg.node, args=( msg.qname, msg.alias, msg_future_import if msg.parent_subscript else "", ), ) # Clear all module cache variables self._alias_name_collisions.clear() self._consider_using_alias_msgs.clear()
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/typing.py
pylint/extensions/typing.py
168
_check_for_typing_alias
ref
function
self._check_for_typing_alias(node)
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/typing.py
pylint/extensions/typing.py
170
_check_for_alternative_union_syntax
ref
function
self._check_for_alternative_union_syntax(node, node.name)
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/typing.py
pylint/extensions/typing.py
172
check_messages
ref
function
@check_messages(
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/typing.py
pylint/extensions/typing.py
177
visit_attribute
def
function
def visit_attribute(self, node: nodes.Attribute) -> None: if self._should_check_typing_alias and node.attrname in ALIAS_NAMES: self._check_for_typing_alias(node) if self._should_check_alternative_union_syntax and node.attrname in UNION_NAMES: self._check_for_alternative_union_syntax(node, node.attrname) def _check_for_alternative_union_syntax( self, node: Union[nodes.Name, nodes.Attribute], name: str, ) -> None: """Check if alternative union syntax could be used. Requires - Python 3.10 - OR: Python 3.7+ with postponed evaluation in a type annotation context """ inferred = safe_infer(node) if not ( isinstance(inferred, nodes.FunctionDef) and inferred.qname() in {"typing.Optional", "typing.Union"} or isinstance(inferred, astroid.bases.Instance) and inferred.qname() == "typing._SpecialForm" ): return if not (self._py310_plus or is_node_in_type_annotation_context(node)): return self.add_message( "consider-alternative-union-syntax", node=node, args=(name, self._msg_postponed_eval_hint(node)), ) def _check_for_typing_alias( self, node: Union[nodes.Name, nodes.Attribute], ) -> None: """Check if typing alias is deprecated or could be replaced. Requires - Python 3.9 - OR: Python 3.7+ with postponed evaluation in a type annotation context For Python 3.7+: Only emit message if change doesn't create any name collisions, only ever used in a type annotation context, and can safely be replaced. """ inferred = safe_infer(node) if not isinstance(inferred, nodes.ClassDef): return alias = DEPRECATED_TYPING_ALIASES.get(inferred.qname(), None) if alias is None: return if self._py39_plus: self.add_message( "deprecated-typing-alias", node=node, args=(inferred.qname(), alias.name), ) return # For PY37+, check for type annotation context first if not is_node_in_type_annotation_context(node) and isinstance( node.parent, nodes.Subscript ): if alias.name_collision is _True: self._alias_name_collisions.add(inferred.qname()) return self._consider_using_alias_msgs.append( DeprecatedTypingAliasMsg( node, inferred.qname(), alias.name, isinstance(node.parent, nodes.Subscript), ) ) @check_messages("consider-using-alias") def leave_module(self, node: nodes.Module) -> None: """After parsing of module is complete, add messages for 'consider-using-alias' check. Make sure results are safe to recommend / collision free. """ if self._py37_plus and not self._py39_plus: msg_future_import = self._msg_postponed_eval_hint(node) for msg in self._consider_using_alias_msgs: if msg.qname in self._alias_name_collisions: continue self.add_message( "consider-using-alias", node=msg.node, args=( msg.qname, msg.alias, msg_future_import if msg.parent_subscript else "", ), ) # Clear all module cache variables self._alias_name_collisions.clear() self._consider_using_alias_msgs.clear()
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/typing.py
pylint/extensions/typing.py
179
_check_for_typing_alias
ref
function
self._check_for_typing_alias(node)
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/typing.py
pylint/extensions/typing.py
181
_check_for_alternative_union_syntax
ref
function
self._check_for_alternative_union_syntax(node, node.attrname)
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/typing.py
pylint/extensions/typing.py
183
_check_for_alternative_union_syntax
def
function
def _check_for_alternative_union_syntax( self, node: Union[nodes.Name, nodes.Attribute], name: str, ) -> None: """Check if alternative union syntax could be used. Requires - Python 3.10 - OR: Python 3.7+ with postponed evaluation in a type annotation context """ inferred = safe_infer(node) if not ( isinstance(inferred, nodes.FunctionDef) and inferred.qname() in {"typing.Optional", "typing.Union"} or isinstance(inferred, astroid.bases.Instance) and inferred.qname() == "typing._SpecialForm" ): return if not (self._py310_plus or is_node_in_type_annotation_context(node)): return self.add_message( "consider-alternative-union-syntax", node=node, args=(name, self._msg_postponed_eval_hint(node)), ) def _check_for_typing_alias( self, node: Union[nodes.Name, nodes.Attribute], ) -> None: """Check if typing alias is deprecated or could be replaced. Requires - Python 3.9 - OR: Python 3.7+ with postponed evaluation in a type annotation context For Python 3.7+: Only emit message if change doesn't create any name collisions, only ever used in a type annotation context, and can safely be replaced. """ inferred = safe_infer(node) if not isinstance(inferred, nodes.ClassDef): return alias = DEPRECATED_TYPING_ALIASES.get(inferred.qname(), None) if alias is None: return if self._py39_plus: self.add_message( "deprecated-typing-alias", node=node, args=(inferred.qname(), alias.name), ) return # For PY37+, check for type annotation context first if not is_node_in_type_annotation_context(node) and isinstance( node.parent, nodes.Subscript ): if alias.name_collision is _True: self._alias_name_collisions.add(inferred.qname()) return self._consider_using_alias_msgs.append( DeprecatedTypingAliasMsg( node, inferred.qname(), alias.name, isinstance(node.parent, nodes.Subscript), ) ) @check_messages("consider-using-alias") def leave_module(self, node: nodes.Module) -> None: """After parsing of module is complete, add messages for 'consider-using-alias' check. Make sure results are safe to recommend / collision free. """ if self._py37_plus and not self._py39_plus: msg_future_import = self._msg_postponed_eval_hint(node) for msg in self._consider_using_alias_msgs: if msg.qname in self._alias_name_collisions: continue self.add_message( "consider-using-alias", node=msg.node, args=( msg.qname, msg.alias, msg_future_import if msg.parent_subscript else "", ), ) # Clear all module cache variables self._alias_name_collisions.clear() self._consider_using_alias_msgs.clear()
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/typing.py
pylint/extensions/typing.py
195
safe_infer
ref
function
inferred = safe_infer(node)
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/typing.py
pylint/extensions/typing.py
198
qname
ref
function
and inferred.qname() in {"typing.Optional", "typing.Union"}
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/typing.py
pylint/extensions/typing.py
200
qname
ref
function
and inferred.qname() == "typing._SpecialForm"
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/typing.py
pylint/extensions/typing.py
203
is_node_in_type_annotation_context
ref
function
if not (self._py310_plus or is_node_in_type_annotation_context(node)):
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/typing.py
pylint/extensions/typing.py
205
add_message
ref
function
self.add_message(
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/typing.py
pylint/extensions/typing.py
208
_msg_postponed_eval_hint
ref
function
args=(name, self._msg_postponed_eval_hint(node)),
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/typing.py
pylint/extensions/typing.py
211
_check_for_typing_alias
def
function
def _check_for_typing_alias( self, node: Union[nodes.Name, nodes.Attribute], ) -> None: """Check if typing alias is deprecated or could be replaced. Requires - Python 3.9 - OR: Python 3.7+ with postponed evaluation in a type annotation context For Python 3.7+: Only emit message if change doesn't create any name collisions, only ever used in a type annotation context, and can safely be replaced. """ inferred = safe_infer(node) if not isinstance(inferred, nodes.ClassDef): return alias = DEPRECATED_TYPING_ALIASES.get(inferred.qname(), None) if alias is None: return if self._py39_plus: self.add_message( "deprecated-typing-alias", node=node, args=(inferred.qname(), alias.name), ) return # For PY37+, check for type annotation context first if not is_node_in_type_annotation_context(node) and isinstance( node.parent, nodes.Subscript ): if alias.name_collision is _True: self._alias_name_collisions.add(inferred.qname()) return self._consider_using_alias_msgs.append( DeprecatedTypingAliasMsg( node, inferred.qname(), alias.name, isinstance(node.parent, nodes.Subscript), ) ) @check_messages("consider-using-alias") def leave_module(self, node: nodes.Module) -> None: """After parsing of module is complete, add messages for 'consider-using-alias' check. Make sure results are safe to recommend / collision free. """ if self._py37_plus and not self._py39_plus: msg_future_import = self._msg_postponed_eval_hint(node) for msg in self._consider_using_alias_msgs: if msg.qname in self._alias_name_collisions: continue self.add_message( "consider-using-alias", node=msg.node, args=( msg.qname, msg.alias, msg_future_import if msg.parent_subscript else "", ), ) # Clear all module cache variables self._alias_name_collisions.clear() self._consider_using_alias_msgs.clear()
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/typing.py
pylint/extensions/typing.py
226
safe_infer
ref
function
inferred = safe_infer(node)