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/checkers/utils.py | pylint/checkers/utils.py | 1,287 | has_known_bases | def | function | def has_known_bases(klass: nodes.ClassDef, context=None) -> bool:
"""Return true if all base classes of a class could be inferred."""
try:
return klass._all_bases_known
except AttributeError:
pass
for base in klass.bases:
result = safe_infer(base, context=context)
if (
not isinstance(result, nodes.ClassDef)
or result is klass
or not has_known_bases(result, context=context)
):
klass._all_bases_known = _False
return _False
klass._all_bases_known = _True
return _True
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/utils.py | pylint/checkers/utils.py | 1,294 | safe_infer | ref | function | result = safe_infer(base, context=context)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/utils.py | pylint/checkers/utils.py | 1,298 | has_known_bases | ref | function | or not has_known_bases(result, context=context)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/utils.py | pylint/checkers/utils.py | 1,306 | is_none | def | function | def is_none(node: nodes.NodeNG) -> bool:
return (
node is None
or (isinstance(node, nodes.Const) and node.value is None)
or (isinstance(node, nodes.Name) and node.name == "None")
)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/utils.py | pylint/checkers/utils.py | 1,314 | node_type | def | function | def node_type(node: nodes.NodeNG) -> Optional[nodes.NodeNG]:
"""Return the inferred type for `node`.
If there is more than one possible type, or if inferred type is Uninferable or None,
return None
"""
# check there is only one possible type for the assign node. Else we
# don't handle it for now
types: Set[nodes.NodeNG] = set()
try:
for var_type in node.infer():
if var_type == astroid.Uninferable or is_none(var_type):
continue
types.add(var_type)
if len(types) > 1:
return None
except astroid.InferenceError:
return None
return types.pop() if types else None
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/utils.py | pylint/checkers/utils.py | 1,324 | infer | ref | function | for var_type in node.infer():
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/utils.py | pylint/checkers/utils.py | 1,325 | is_none | ref | function | if var_type == astroid.Uninferable or is_none(var_type):
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/utils.py | pylint/checkers/utils.py | 1,335 | is_registered_in_singledispatch_function | def | function | def is_registered_in_singledispatch_function(node: nodes.FunctionDef) -> bool:
"""Check if the given function node is a singledispatch function."""
singledispatch_qnames = (
"functools.singledispatch",
"singledispatch.singledispatch",
)
if not isinstance(node, nodes.FunctionDef):
return _False
decorators = node.decorators.nodes if node.decorators else []
for decorator in decorators:
# func.register are function calls
if not isinstance(decorator, nodes.Call):
continue
func = decorator.func
if not isinstance(func, nodes.Attribute) or func.attrname != "register":
continue
try:
func_def = next(func.expr.infer())
except astroid.InferenceError:
continue
if isinstance(func_def, nodes.FunctionDef):
return decorated_with(func_def, singledispatch_qnames)
return _False
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/utils.py | pylint/checkers/utils.py | 1,357 | infer | ref | function | func_def = next(func.expr.infer())
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/utils.py | pylint/checkers/utils.py | 1,362 | decorated_with | ref | function | return decorated_with(func_def, singledispatch_qnames)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/utils.py | pylint/checkers/utils.py | 1,367 | get_node_last_lineno | def | function | def get_node_last_lineno(node: nodes.NodeNG) -> int:
"""Get the last lineno of the given node. For a simple statement this will just be node.lineno,
but for a node that has child statements (e.g. a method) this will be the lineno of the last
child statement recursively.
"""
# 'finalbody' is always the last clause in a try statement, if present
if getattr(node, "finalbody", _False):
return get_node_last_lineno(node.finalbody[-1])
# For if, while, and for statements 'orelse' is always the last clause.
# For try statements 'orelse' is the last in the absence of a 'finalbody'
if getattr(node, "orelse", _False):
return get_node_last_lineno(node.orelse[-1])
# try statements have the 'handlers' last if there is no 'orelse' or 'finalbody'
if getattr(node, "handlers", _False):
return get_node_last_lineno(node.handlers[-1])
# All compound statements have a 'body'
if getattr(node, "body", _False):
return get_node_last_lineno(node.body[-1])
# Not a compound statement
return node.lineno
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/utils.py | pylint/checkers/utils.py | 1,374 | get_node_last_lineno | ref | function | return get_node_last_lineno(node.finalbody[-1])
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/utils.py | pylint/checkers/utils.py | 1,378 | get_node_last_lineno | ref | function | return get_node_last_lineno(node.orelse[-1])
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/utils.py | pylint/checkers/utils.py | 1,381 | get_node_last_lineno | ref | function | return get_node_last_lineno(node.handlers[-1])
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/utils.py | pylint/checkers/utils.py | 1,384 | get_node_last_lineno | ref | function | return get_node_last_lineno(node.body[-1])
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/utils.py | pylint/checkers/utils.py | 1,389 | is_postponed_evaluation_enabled | def | function | def is_postponed_evaluation_enabled(node: nodes.NodeNG) -> bool:
"""Check if the postponed evaluation of annotations is enabled."""
module = node.root()
return "annotations" in module.future_imports
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/utils.py | pylint/checkers/utils.py | 1,391 | root | ref | function | module = node.root()
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/utils.py | pylint/checkers/utils.py | 1,395 | is_class_subscriptable_pep585_with_postponed_evaluation_enabled | def | class | |
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/utils.py | pylint/checkers/utils.py | 1,402 | is_postponed_evaluation_enabled | ref | function | is_postponed_evaluation_enabled(node)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/utils.py | pylint/checkers/utils.py | 1,403 | qname | ref | function | and value.qname() in SUBSCRIPTABLE_CLASSES_PEP585
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/utils.py | pylint/checkers/utils.py | 1,404 | is_node_in_type_annotation_context | ref | function | and is_node_in_type_annotation_context(node)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/utils.py | pylint/checkers/utils.py | 1,408 | is_node_in_type_annotation_context | def | function | def is_node_in_type_annotation_context(node: nodes.NodeNG) -> bool:
"""Check if node is in type annotation context.
Check for 'AnnAssign', function 'Arguments',
or part of function return type anntation.
"""
# pylint: disable=too-many-boolean-expressions
current_node, parent_node = node, node.parent
while _True:
if (
isinstance(parent_node, nodes.AnnAssign)
and parent_node.annotation == current_node
or isinstance(parent_node, nodes.Arguments)
and current_node
in (
*parent_node.annotations,
*parent_node.posonlyargs_annotations,
*parent_node.kwonlyargs_annotations,
parent_node.varargannotation,
parent_node.kwargannotation,
)
or isinstance(parent_node, nodes.FunctionDef)
and parent_node.returns == current_node
):
return _True
current_node, parent_node = parent_node, parent_node.parent
if isinstance(parent_node, nodes.Module):
return _False
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/utils.py | pylint/checkers/utils.py | 1,438 | is_subclass_of | def | class | |
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/utils.py | pylint/checkers/utils.py | 1,447 | ancestors | ref | function | for ancestor in child.ancestors():
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/utils.py | pylint/checkers/utils.py | 1,449 | is_subtype | ref | function | if astroid.helpers.is_subtype(ancestor, parent):
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/utils.py | pylint/checkers/utils.py | 1,457 | is_overload_stub | def | function | def is_overload_stub(node: nodes.NodeNG) -> bool:
"""Check if a node is a function stub decorated with typing.overload.
:param node: Node to check.
:returns: _True if node is an overload function stub. _False otherwise.
"""
decorators = getattr(node, "decorators", None)
return bool(decorators and decorated_with(node, ["typing.overload", "overload"]))
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/utils.py | pylint/checkers/utils.py | 1,464 | decorated_with | ref | function | return bool(decorators and decorated_with(node, ["typing.overload", "overload"]))
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/utils.py | pylint/checkers/utils.py | 1,467 | is_protocol_class | def | class | |
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/utils.py | pylint/checkers/utils.py | 1,478 | qname | ref | function | return any(parent.qname() in TYPING_PROTOCOLS for parent in cls.ancestors())
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/utils.py | pylint/checkers/utils.py | 1,478 | ancestors | ref | function | return any(parent.qname() in TYPING_PROTOCOLS for parent in cls.ancestors())
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/utils.py | pylint/checkers/utils.py | 1,481 | is_call_of_name | def | function | def is_call_of_name(node: nodes.NodeNG, name: str) -> bool:
"""Checks if node is a function call with the given name."""
return (
isinstance(node, nodes.Call)
and isinstance(node.func, nodes.Name)
and node.func.name == name
)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/utils.py | pylint/checkers/utils.py | 1,490 | is_test_condition | def | function | def is_test_condition(
node: nodes.NodeNG,
parent: Optional[nodes.NodeNG] = None,
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/utils.py | pylint/checkers/utils.py | 1,497 | parent_of | ref | function | return node is parent.test or parent.test.parent_of(node)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/utils.py | pylint/checkers/utils.py | 1,500 | is_call_of_name | ref | function | return is_call_of_name(parent, "bool") and parent.parent_of(node)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/utils.py | pylint/checkers/utils.py | 1,500 | parent_of | ref | function | return is_call_of_name(parent, "bool") and parent.parent_of(node)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/utils.py | pylint/checkers/utils.py | 1,503 | is_classdef_type | def | class | |
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/utils.py | pylint/checkers/utils.py | 1,510 | is_attribute_typed_annotation | def | function | def is_attribute_typed_annotation(
node: Union[nodes.ClassDef, astroid.Instance], attr_name: str
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/utils.py | pylint/checkers/utils.py | 1,524 | safe_infer | ref | function | inferred = safe_infer(base)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/utils.py | pylint/checkers/utils.py | 1,528 | is_attribute_typed_annotation | ref | function | and is_attribute_typed_annotation(inferred, attr_name)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/utils.py | pylint/checkers/utils.py | 1,534 | is_assign_name_annotated_with | def | function | def is_assign_name_annotated_with(node: nodes.AssignName, typing_name: str) -> bool:
"""Test if AssignName node has `typing_name` annotation.
Especially useful to check for `typing._SpecialForm` instances
like: `Union`, `Optional`, `Literal`, `ClassVar`, `Final`.
"""
if not isinstance(node.parent, nodes.AnnAssign):
return _False
annotation = node.parent.annotation
if isinstance(annotation, nodes.Subscript):
annotation = annotation.value
if (
isinstance(annotation, nodes.Name)
and annotation.name == typing_name
or isinstance(annotation, nodes.Attribute)
and annotation.attrname == typing_name
):
return _True
return _False
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/utils.py | pylint/checkers/utils.py | 1,555 | get_iterating_dictionary_name | def | function | def get_iterating_dictionary_name(
node: Union[nodes.For, nodes.Comprehension]
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/utils.py | pylint/checkers/utils.py | 1,570 | safe_infer | ref | function | inferred = safe_infer(node.iter.func)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/utils.py | pylint/checkers/utils.py | 1,573 | as_string | ref | function | return node.iter.as_string().rpartition(".keys")[0]
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/utils.py | pylint/checkers/utils.py | 1,577 | safe_infer | ref | function | inferred = safe_infer(node.iter)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/utils.py | pylint/checkers/utils.py | 1,580 | as_string | ref | function | return node.iter.as_string()
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/utils.py | pylint/checkers/utils.py | 1,585 | get_subscript_const_value | def | function | def get_subscript_const_value(node: nodes.Subscript) -> nodes.Const:
"""Returns the value 'subscript.slice' of a Subscript node.
:param node: Subscript Node to extract value from
:returns: Const Node containing subscript value
:raises InferredTypeError: if the subscript node cannot be inferred as a Const
"""
inferred = safe_infer(node.slice)
if not isinstance(inferred, nodes.Const):
raise InferredTypeError("Subscript.slice cannot be inferred as a nodes.Const")
return inferred
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/utils.py | pylint/checkers/utils.py | 1,592 | safe_infer | ref | function | inferred = safe_infer(node.slice)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/utils.py | pylint/checkers/utils.py | 1,594 | InferredTypeError | ref | function | raise InferredTypeError("Subscript.slice cannot be inferred as a nodes.Const")
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/utils.py | pylint/checkers/utils.py | 1,599 | get_import_name | def | function | def get_import_name(
importnode: Union[nodes.Import, nodes.ImportFrom], modname: str
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/utils.py | pylint/checkers/utils.py | 1,615 | root | ref | function | root = importnode.root()
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/utils.py | pylint/checkers/utils.py | 1,618 | relative_to_absolute_name | ref | function | return root.relative_to_absolute_name(modname, level=importnode.level)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/utils.py | pylint/checkers/utils.py | 1,624 | is_sys_guard | def | function | def is_sys_guard(node: nodes.If) -> bool:
"""Return _True if IF stmt is a sys.version_info guard.
>>> import sys
>>> if sys.version_info > (3, 8):
>>> from typing import Literal
>>> else:
>>> from typing_extensions import Literal
"""
if isinstance(node.test, nodes.Compare):
value = node.test.left
if isinstance(value, nodes.Subscript):
value = value.value
if (
isinstance(value, nodes.Attribute)
and value.as_string() == "sys.version_info"
):
return _True
return _False
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/utils.py | pylint/checkers/utils.py | 1,639 | as_string | ref | function | and value.as_string() == "sys.version_info"
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/utils.py | pylint/checkers/utils.py | 1,646 | is_typing_guard | def | function | def is_typing_guard(node: nodes.If) -> bool:
"""Return _True if IF stmt is a typing guard.
>>> from typing import TYPE_CHECKING
>>> if TYPE_CHECKING:
>>> from xyz import a
"""
return isinstance(
node.test, (nodes.Name, nodes.Attribute)
) and node.test.as_string().endswith("TYPE_CHECKING")
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/utils.py | pylint/checkers/utils.py | 1,655 | as_string | ref | function | ) and node.test.as_string().endswith("TYPE_CHECKING")
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/utils.py | pylint/checkers/utils.py | 1,658 | is_node_in_guarded_import_block | def | function | def is_node_in_guarded_import_block(node: nodes.NodeNG) -> bool:
"""Return _True if node is part for guarded if block.
I.e. `sys.version_info` or `typing.TYPE_CHECKING`
"""
return isinstance(node.parent, nodes.If) and (
is_sys_guard(node.parent) or is_typing_guard(node.parent)
)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/utils.py | pylint/checkers/utils.py | 1,663 | is_sys_guard | ref | function | is_sys_guard(node.parent) or is_typing_guard(node.parent)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/utils.py | pylint/checkers/utils.py | 1,663 | is_typing_guard | ref | function | is_sys_guard(node.parent) or is_typing_guard(node.parent)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/utils.py | pylint/checkers/utils.py | 1,667 | is_reassigned_after_current | def | function | def is_reassigned_after_current(node: nodes.NodeNG, varname: str) -> bool:
"""Check if the given variable name is reassigned in the same scope after the current node."""
return any(
a.name == varname and a.lineno > node.lineno
for a in node.scope().nodes_of_class(
(nodes.AssignName, nodes.ClassDef, nodes.FunctionDef)
)
)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/utils.py | pylint/checkers/utils.py | 1,671 | scope | ref | class | |
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/utils.py | pylint/checkers/utils.py | 1,671 | nodes_of_class | ref | class | |
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/utils.py | pylint/checkers/utils.py | 1,677 | is_deleted_after_current | def | function | def is_deleted_after_current(node: nodes.NodeNG, varname: str) -> bool:
"""Check if the given variable name is deleted in the same scope after the current node."""
return any(
getattr(target, "name", None) == varname and target.lineno > node.lineno
for del_node in node.scope().nodes_of_class(nodes.Delete)
for target in del_node.targets
)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/utils.py | pylint/checkers/utils.py | 1,681 | scope | ref | class | |
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/utils.py | pylint/checkers/utils.py | 1,681 | nodes_of_class | ref | class | |
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/utils.py | pylint/checkers/utils.py | 1,686 | is_function_body_ellipsis | def | function | def is_function_body_ellipsis(node: nodes.FunctionDef) -> bool:
"""Checks whether a function body only consists of a single Ellipsis."""
return (
len(node.body) == 1
and isinstance(node.body[0], nodes.Expr)
and isinstance(node.body[0].value, nodes.Const)
and node.body[0].value.value == Ellipsis
)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/utils.py | pylint/checkers/utils.py | 1,696 | is_base_container | def | function | def is_base_container(node: Optional[nodes.NodeNG]) -> bool:
return isinstance(node, nodes.BaseContainer) and not node.elts
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/utils.py | pylint/checkers/utils.py | 1,700 | is_empty_dict_literal | def | function | def is_empty_dict_literal(node: Optional[nodes.NodeNG]) -> bool:
return isinstance(node, nodes.Dict) and not node.items
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/utils.py | pylint/checkers/utils.py | 1,704 | is_empty_str_literal | def | function | def is_empty_str_literal(node: Optional[nodes.NodeNG]) -> bool:
return (
isinstance(node, nodes.Const) and isinstance(node.value, str) and not node.value
)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/utils.py | pylint/checkers/utils.py | 1,710 | returns_bool | def | function | def returns_bool(node: nodes.NodeNG) -> bool:
"""Returns true if a node is a return that returns a constant boolean."""
return (
isinstance(node, nodes.Return)
and isinstance(node.value, nodes.Const)
and node.value.value in {_True, _False}
)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/utils.py | pylint/checkers/utils.py | 1,719 | get_node_first_ancestor_of_type | def | function | def get_node_first_ancestor_of_type(
node: nodes.NodeNG, ancestor_type: Union[Type[T_Node], Tuple[Type[T_Node], ...]]
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/utils.py | pylint/checkers/utils.py | 1,723 | node_ancestors | ref | function | for ancestor in node.node_ancestors():
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/utils.py | pylint/checkers/utils.py | 1,729 | get_node_first_ancestor_of_type_and_its_child | def | function | def get_node_first_ancestor_of_type_and_its_child(
node: nodes.NodeNG, ancestor_type: Union[Type[T_Node], Tuple[Type[T_Node], ...]]
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/utils.py | pylint/checkers/utils.py | 1,738 | node_ancestors | ref | function | for ancestor in node.node_ancestors():
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/variables.py | pylint/checkers/variables.py | 165 | VariableVisitConsumerAction | def | class | |
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/variables.py | pylint/checkers/variables.py | 177 | _is_from_future_import | def | function | def _is_from_future_import(stmt, name):
"""Check if the name is a future import from another module."""
try:
module = stmt.do_import_module(stmt.modname)
except astroid.AstroidBuildingException:
return None
for local_node in module.locals.get(name, []):
if isinstance(local_node, nodes.ImportFrom) and local_node.modname == FUTURE:
return _True
return None
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/variables.py | pylint/checkers/variables.py | 180 | do_import_module | ref | function | module = stmt.do_import_module(stmt.modname)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/variables.py | pylint/checkers/variables.py | 190 | in_for_else_branch | def | function | def in_for_else_branch(parent, stmt):
"""Returns _True if stmt in inside the else branch for a parent For stmt."""
return isinstance(parent, nodes.For) and any(
else_stmt.parent_of(stmt) or else_stmt == stmt for else_stmt in parent.orelse
)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/variables.py | pylint/checkers/variables.py | 193 | parent_of | ref | function | else_stmt.parent_of(stmt) or else_stmt == stmt for else_stmt in parent.orelse
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/variables.py | pylint/checkers/variables.py | 198 | overridden_method | def | function | def overridden_method(klass, name):
"""Get overridden method if any."""
try:
parent = next(klass.local_attr_ancestors(name))
except (StopIteration, KeyError):
return None
try:
meth_node = parent[name]
except KeyError:
# We have found an ancestor defining <name> but it's not in the local
# dictionary. This may happen with astroid built from living objects.
return None
if isinstance(meth_node, nodes.FunctionDef):
return meth_node
return None
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/variables.py | pylint/checkers/variables.py | 201 | local_attr_ancestors | ref | function | parent = next(klass.local_attr_ancestors(name))
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/variables.py | pylint/checkers/variables.py | 215 | _get_unpacking_extra_info | def | function | def _get_unpacking_extra_info(node, inferred):
"""Return extra information to add to the message for unpacking-non-sequence
and unbalanced-tuple-unpacking errors
"""
more = ""
inferred_module = inferred.root().name
if node.root().name == inferred_module:
if node.lineno == inferred.lineno:
more = f" {inferred.as_string()}"
elif inferred.lineno:
more = f" defined at line {inferred.lineno}"
elif inferred.lineno:
more = f" defined at line {inferred.lineno} of {inferred_module}"
return more
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/variables.py | pylint/checkers/variables.py | 220 | root | ref | function | inferred_module = inferred.root().name
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/variables.py | pylint/checkers/variables.py | 221 | root | ref | function | if node.root().name == inferred_module:
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/variables.py | pylint/checkers/variables.py | 223 | as_string | ref | function | more = f" {inferred.as_string()}"
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/variables.py | pylint/checkers/variables.py | 231 | _detect_global_scope | def | function | def _detect_global_scope(node, frame, defframe):
"""Detect that the given frames shares a global
scope.
Two frames shares a global scope when neither
of them are hidden under a function scope, as well
as any of parent scope of them, until the root scope.
In this case, depending from something defined later on
will not work, because it is still undefined.
Example:
class A:
# B has the same global scope as `C`, leading to a NameError.
class B(C): ...
class C: ...
"""
def_scope = scope = None
if frame and frame.parent:
scope = frame.parent.scope()
if defframe and defframe.parent:
def_scope = defframe.parent.scope()
if isinstance(frame, nodes.FunctionDef):
# If the parent of the current node is a
# function, then it can be under its scope
# (defined in, which doesn't concern us) or
# the `->` part of annotations. The same goes
# for annotations of function arguments, they'll have
# their parent the Arguments node.
if not isinstance(node.parent, (nodes.FunctionDef, nodes.Arguments)):
return _False
elif any(
not isinstance(f, (nodes.ClassDef, nodes.Module)) for f in (frame, defframe)
):
# Not interested in other frames, since they are already
# not in a global scope.
return _False
break_scopes = []
for current_scope in (scope, def_scope):
# Look for parent scopes. If there is anything different
# than a module or a class scope, then they frames don't
# share a global scope.
parent_scope = current_scope
while parent_scope:
if not isinstance(parent_scope, (nodes.ClassDef, nodes.Module)):
break_scopes.append(parent_scope)
break
if parent_scope.parent:
parent_scope = parent_scope.parent.scope()
else:
break
if break_scopes and len(set(break_scopes)) != 1:
# Store different scopes than expected.
# If the stored scopes are, in fact, the very same, then it means
# that the two frames (frame and defframe) shares the same scope,
# and we could apply our lineno analysis over them.
# For instance, this works when they are inside a function, the node
# that uses a definition and the definition itself.
return _False
# At this point, we are certain that frame and defframe shares a scope
# and the definition of the first depends on the second.
return frame.lineno < defframe.lineno
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/variables.py | pylint/checkers/variables.py | 250 | scope | ref | function | scope = frame.parent.scope()
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/variables.py | pylint/checkers/variables.py | 252 | scope | ref | function | def_scope = defframe.parent.scope()
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/variables.py | pylint/checkers/variables.py | 280 | scope | ref | function | parent_scope = parent_scope.parent.scope()
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/variables.py | pylint/checkers/variables.py | 296 | _infer_name_module | def | function | def _infer_name_module(node, name):
context = astroid.context.InferenceContext()
context.lookupname = name
return node.infer(context, asname=_False)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/variables.py | pylint/checkers/variables.py | 297 | InferenceContext | ref | function | context = astroid.context.InferenceContext()
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/variables.py | pylint/checkers/variables.py | 299 | infer | ref | function | return node.infer(context, asname=False)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/variables.py | pylint/checkers/variables.py | 302 | _fix_dot_imports | def | function | def _fix_dot_imports(not_consumed):
"""Try to fix imports with multiple dots, by returning a dictionary
with the import names expanded. The function unflattens root imports,
like 'xml' (when we have both 'xml.etree' and 'xml.sax'), to 'xml.etree'
and 'xml.sax' respectively.
"""
names = {}
for name, stmts in not_consumed.items():
if any(
isinstance(stmt, nodes.AssignName)
and isinstance(stmt.assign_type(), nodes.AugAssign)
for stmt in stmts
):
continue
for stmt in stmts:
if not isinstance(stmt, (nodes.ImportFrom, nodes.Import)):
continue
for imports in stmt.names:
second_name = None
import_module_name = imports[0]
if import_module_name == "*":
# In case of wildcard imports,
# pick the name from inside the imported module.
second_name = name
else:
name_matches_dotted_import = _False
if (
import_module_name.startswith(name)
and import_module_name.find(".") > -1
):
name_matches_dotted_import = _True
if name_matches_dotted_import or name in imports:
# Most likely something like 'xml.etree',
# which will appear in the .locals as 'xml'.
# Only pick the name if it wasn't consumed.
second_name = import_module_name
if second_name and second_name not in names:
names[second_name] = stmt
return sorted(names.items(), key=lambda a: a[1].fromlineno)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/variables.py | pylint/checkers/variables.py | 312 | assign_type | ref | function | and isinstance(stmt.assign_type(), nodes.AugAssign)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/variables.py | pylint/checkers/variables.py | 344 | _find_frame_imports | def | function | def _find_frame_imports(name, frame):
"""Detect imports in the frame, with the required
*name*. Such imports can be considered assignments.
Returns _True if an import for the given name was found.
"""
imports = frame.nodes_of_class((nodes.Import, nodes.ImportFrom))
for import_node in imports:
for import_name, import_alias in import_node.names:
# If the import uses an alias, check only that.
# Otherwise, check only the import name.
if import_alias:
if import_alias == name:
return _True
elif import_name and import_name == name:
return _True
return None
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/variables.py | pylint/checkers/variables.py | 349 | nodes_of_class | ref | class | |
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/variables.py | pylint/checkers/variables.py | 362 | _import_name_is_global | def | function | def _import_name_is_global(stmt, global_names):
for import_name, import_alias in stmt.names:
# If the import uses an alias, check only that.
# Otherwise, check only the import name.
if import_alias:
if import_alias in global_names:
return _True
elif import_name in global_names:
return _True
return _False
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/variables.py | pylint/checkers/variables.py | 374 | _flattened_scope_names | def | function | def _flattened_scope_names(iterator):
values = (set(stmt.names) for stmt in iterator)
return set(itertools.chain.from_iterable(values))
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/variables.py | pylint/checkers/variables.py | 376 | from_iterable | ref | function | return set(itertools.chain.from_iterable(values))
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/variables.py | pylint/checkers/variables.py | 379 | _assigned_locally | def | function | def _assigned_locally(name_node):
"""Checks if name_node has corresponding assign statement in same scope."""
assign_stmts = name_node.scope().nodes_of_class(nodes.AssignName)
return any(a.name == name_node.name for a in assign_stmts)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/variables.py | pylint/checkers/variables.py | 381 | scope | ref | class |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.