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/docstyle.py | pylint/extensions/docstyle.py | 47 | visit_module | def | function | def visit_module(self, node: nodes.Module) -> None:
self._check_docstring("module", node)
def visit_classdef(self, node: nodes.ClassDef) -> None:
self._check_docstring("class", node)
def visit_functiondef(self, node: nodes.FunctionDef) -> None:
ftype = "method" if node.is_method() else "function"
self._check_docstring(ftype, node)
visit_asyncfunctiondef = visit_functiondef
def _check_docstring(self, node_type, node):
docstring = node.doc
if docstring and docstring[0] == "\n":
self.add_message(
"docstring-first-line-empty",
node=node,
args=(node_type,),
confidence=HIGH,
)
# Use "linecache", instead of node.as_string(), because the latter
# looses the original form of the docstrings.
if docstring:
lineno = node.fromlineno + 1
line = linecache.getline(node.root().file, lineno).lstrip()
if line and line.find('"""') == 0:
return
if line and "'''" in line:
quotes = "'''"
elif line and line[0] == '"':
quotes = '"'
elif line and line[0] == "'":
quotes = "'"
else:
quotes = _False
if quotes and PY38_PLUS:
self.add_message(
"bad-docstring-quotes",
node=node,
args=(node_type, quotes),
confidence=HIGH,
)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/docstyle.py | pylint/extensions/docstyle.py | 48 | _check_docstring | ref | function | self._check_docstring("module", node)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/docstyle.py | pylint/extensions/docstyle.py | 50 | visit_classdef | def | class | |
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/docstyle.py | pylint/extensions/docstyle.py | 51 | _check_docstring | ref | class | |
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/docstyle.py | pylint/extensions/docstyle.py | 53 | visit_functiondef | def | function | def visit_functiondef(self, node: nodes.FunctionDef) -> None:
ftype = "method" if node.is_method() else "function"
self._check_docstring(ftype, node)
visit_asyncfunctiondef = visit_functiondef
def _check_docstring(self, node_type, node):
docstring = node.doc
if docstring and docstring[0] == "\n":
self.add_message(
"docstring-first-line-empty",
node=node,
args=(node_type,),
confidence=HIGH,
)
# Use "linecache", instead of node.as_string(), because the latter
# looses the original form of the docstrings.
if docstring:
lineno = node.fromlineno + 1
line = linecache.getline(node.root().file, lineno).lstrip()
if line and line.find('"""') == 0:
return
if line and "'''" in line:
quotes = "'''"
elif line and line[0] == '"':
quotes = '"'
elif line and line[0] == "'":
quotes = "'"
else:
quotes = _False
if quotes and PY38_PLUS:
self.add_message(
"bad-docstring-quotes",
node=node,
args=(node_type, quotes),
confidence=HIGH,
)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/docstyle.py | pylint/extensions/docstyle.py | 54 | is_method | ref | function | ftype = "method" if node.is_method() else "function"
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/docstyle.py | pylint/extensions/docstyle.py | 55 | _check_docstring | ref | function | self._check_docstring(ftype, node)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/docstyle.py | pylint/extensions/docstyle.py | 59 | _check_docstring | def | function | def _check_docstring(self, node_type, node):
docstring = node.doc
if docstring and docstring[0] == "\n":
self.add_message(
"docstring-first-line-empty",
node=node,
args=(node_type,),
confidence=HIGH,
)
# Use "linecache", instead of node.as_string(), because the latter
# looses the original form of the docstrings.
if docstring:
lineno = node.fromlineno + 1
line = linecache.getline(node.root().file, lineno).lstrip()
if line and line.find('"""') == 0:
return
if line and "'''" in line:
quotes = "'''"
elif line and line[0] == '"':
quotes = '"'
elif line and line[0] == "'":
quotes = "'"
else:
quotes = _False
if quotes and PY38_PLUS:
self.add_message(
"bad-docstring-quotes",
node=node,
args=(node_type, quotes),
confidence=HIGH,
)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/docstyle.py | pylint/extensions/docstyle.py | 62 | add_message | ref | function | self.add_message(
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/docstyle.py | pylint/extensions/docstyle.py | 74 | root | ref | function | line = linecache.getline(node.root().file, lineno).lstrip()
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/docstyle.py | pylint/extensions/docstyle.py | 86 | add_message | ref | function | self.add_message(
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/docstyle.py | pylint/extensions/docstyle.py | 94 | register | def | function | def register(linter: "PyLinter") -> None:
linter.register_checker(DocStringStyleChecker(linter))
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/docstyle.py | pylint/extensions/docstyle.py | 95 | register_checker | ref | function | linter.register_checker(DocStringStyleChecker(linter))
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/docstyle.py | pylint/extensions/docstyle.py | 95 | DocStringStyleChecker | ref | function | linter.register_checker(DocStringStyleChecker(linter))
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/empty_comment.py | pylint/extensions/empty_comment.py | 11 | is_line_commented | def | function | def is_line_commented(line):
"""Checks if a `# symbol that is not part of a string was found in line."""
comment_idx = line.find(b"#")
if comment_idx == -1:
return _False
if comment_part_of_string(line, comment_idx):
return is_line_commented(line[:comment_idx] + line[comment_idx + 1 :])
return _True
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/empty_comment.py | pylint/extensions/empty_comment.py | 17 | comment_part_of_string | ref | function | if comment_part_of_string(line, comment_idx):
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/empty_comment.py | pylint/extensions/empty_comment.py | 18 | is_line_commented | ref | function | return is_line_commented(line[:comment_idx] + line[comment_idx + 1 :])
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/empty_comment.py | pylint/extensions/empty_comment.py | 22 | comment_part_of_string | def | function | def comment_part_of_string(line, comment_idx):
"""Checks if the symbol at comment_idx is part of a string."""
if (
line[:comment_idx].count(b"'") % 2 == 1
and line[comment_idx:].count(b"'") % 2 == 1
) or (
line[:comment_idx].count(b'"') % 2 == 1
and line[comment_idx:].count(b'"') % 2 == 1
):
return _True
return _False
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/empty_comment.py | pylint/extensions/empty_comment.py | 36 | CommentChecker | def | class | process_module |
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/empty_comment.py | pylint/extensions/empty_comment.py | 52 | process_module | def | function | def process_module(self, node: nodes.Module) -> None:
with node.stream() as stream:
for (line_num, line) in enumerate(stream):
line = line.rstrip()
if line.endswith(b"#"):
if not is_line_commented(line[:-1]):
self.add_message("empty-comment", line=line_num + 1)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/empty_comment.py | pylint/extensions/empty_comment.py | 53 | stream | ref | function | with node.stream() as stream:
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/empty_comment.py | pylint/extensions/empty_comment.py | 57 | is_line_commented | ref | function | if not is_line_commented(line[:-1]):
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/empty_comment.py | pylint/extensions/empty_comment.py | 58 | add_message | ref | function | self.add_message("empty-comment", line=line_num + 1)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/empty_comment.py | pylint/extensions/empty_comment.py | 61 | register | def | function | def register(linter: "PyLinter") -> None:
linter.register_checker(CommentChecker(linter))
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/empty_comment.py | pylint/extensions/empty_comment.py | 62 | register_checker | ref | function | linter.register_checker(CommentChecker(linter))
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/empty_comment.py | pylint/extensions/empty_comment.py | 62 | CommentChecker | ref | function | linter.register_checker(CommentChecker(linter))
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/emptystring.py | pylint/extensions/emptystring.py | 26 | CompareToEmptyStringChecker | def | class | visit_compare |
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/emptystring.py | pylint/extensions/emptystring.py | 48 | check_messages | ref | function | @utils.check_messages("compare-to-empty-string")
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/emptystring.py | pylint/extensions/emptystring.py | 49 | visit_compare | def | function | def visit_compare(self, node: nodes.Compare) -> None:
_operators = ["!=", "==", "is not", "is"]
# note: astroid.Compare has the left most operand in node.left
# while the rest are a list of tuples in node.ops
# the format of the tuple is ('compare operator sign', node)
# here we squash everything into `ops` to make it easier for processing later
ops = [("", node.left)]
ops.extend(node.ops)
iter_ops: Iterable[Any] = iter(ops)
ops = list(itertools.chain(*iter_ops))
for ops_idx in range(len(ops) - 2):
op_1 = ops[ops_idx]
op_2 = ops[ops_idx + 1]
op_3 = ops[ops_idx + 2]
error_detected = _False
# x ?? ""
if utils.is_empty_str_literal(op_1) and op_2 in _operators:
error_detected = _True
# '' ?? X
elif op_2 in _operators and utils.is_empty_str_literal(op_3):
error_detected = _True
if error_detected:
self.add_message("compare-to-empty-string", node=node)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/emptystring.py | pylint/extensions/emptystring.py | 67 | is_empty_str_literal | ref | function | if utils.is_empty_str_literal(op_1) and op_2 in _operators:
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/emptystring.py | pylint/extensions/emptystring.py | 70 | is_empty_str_literal | ref | function | elif op_2 in _operators and utils.is_empty_str_literal(op_3):
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/emptystring.py | pylint/extensions/emptystring.py | 74 | add_message | ref | function | self.add_message("compare-to-empty-string", node=node)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/emptystring.py | pylint/extensions/emptystring.py | 77 | register | def | function | def register(linter: "PyLinter") -> None:
linter.register_checker(CompareToEmptyStringChecker(linter))
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/emptystring.py | pylint/extensions/emptystring.py | 78 | register_checker | ref | function | linter.register_checker(CompareToEmptyStringChecker(linter))
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/emptystring.py | pylint/extensions/emptystring.py | 78 | CompareToEmptyStringChecker | ref | function | linter.register_checker(CompareToEmptyStringChecker(linter))
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/for_any_all.py | pylint/extensions/for_any_all.py | 13 | ConsiderUsingAnyOrAllChecker | def | class | visit_for _build_suggested_string |
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/for_any_all.py | pylint/extensions/for_any_all.py | 25 | check_messages | ref | function | @check_messages("consider-using-any-or-all")
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/for_any_all.py | pylint/extensions/for_any_all.py | 26 | visit_for | def | function | def visit_for(self, node: nodes.For) -> None:
if len(node.body) != 1: # Only If node with no Else
return
if not isinstance(node.body[0], nodes.If):
return
if_children = list(node.body[0].get_children())
if not len(if_children) == 2: # The If node has only a comparison and return
return
if not returns_bool(if_children[1]):
return
# Check for terminating boolean return right after the loop
node_after_loop = node.next_sibling()
if returns_bool(node_after_loop):
final_return_bool = node_after_loop.value.value
suggested_string = self._build_suggested_string(node, final_return_bool)
self.add_message(
"consider-using-any-or-all", node=node, args=suggested_string
)
@staticmethod
def _build_suggested_string(node: nodes.For, final_return_bool: bool) -> str:
"""When a nodes.For node can be rewritten as an any/all statement, return a suggestion for that statement
final_return_bool is the boolean literal returned after the for loop if all conditions fail
"""
loop_var = node.target.as_string()
loop_iter = node.iter.as_string()
test_node = next(node.body[0].get_children())
if isinstance(test_node, nodes.UnaryOp) and test_node.op == "not":
# The condition is negated. Advance the node to the operand and modify the suggestion
test_node = test_node.operand
suggested_function = "all" if final_return_bool else "not all"
else:
suggested_function = "not any" if final_return_bool else "any"
test = test_node.as_string()
return f"{suggested_function}({test} for {loop_var} in {loop_iter})"
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/for_any_all.py | pylint/extensions/for_any_all.py | 32 | get_children | ref | function | if_children = list(node.body[0].get_children())
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/for_any_all.py | pylint/extensions/for_any_all.py | 35 | returns_bool | ref | function | if not returns_bool(if_children[1]):
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/for_any_all.py | pylint/extensions/for_any_all.py | 39 | next_sibling | ref | function | node_after_loop = node.next_sibling()
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/for_any_all.py | pylint/extensions/for_any_all.py | 40 | returns_bool | ref | function | if returns_bool(node_after_loop):
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/for_any_all.py | pylint/extensions/for_any_all.py | 42 | _build_suggested_string | ref | function | suggested_string = self._build_suggested_string(node, final_return_bool)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/for_any_all.py | pylint/extensions/for_any_all.py | 43 | add_message | ref | function | self.add_message(
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/for_any_all.py | pylint/extensions/for_any_all.py | 48 | _build_suggested_string | def | function | def _build_suggested_string(node: nodes.For, final_return_bool: bool) -> str:
"""When a nodes.For node can be rewritten as an any/all statement, return a suggestion for that statement
final_return_bool is the boolean literal returned after the for loop if all conditions fail
"""
loop_var = node.target.as_string()
loop_iter = node.iter.as_string()
test_node = next(node.body[0].get_children())
if isinstance(test_node, nodes.UnaryOp) and test_node.op == "not":
# The condition is negated. Advance the node to the operand and modify the suggestion
test_node = test_node.operand
suggested_function = "all" if final_return_bool else "not all"
else:
suggested_function = "not any" if final_return_bool else "any"
test = test_node.as_string()
return f"{suggested_function}({test} for {loop_var} in {loop_iter})"
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/for_any_all.py | pylint/extensions/for_any_all.py | 52 | as_string | ref | function | loop_var = node.target.as_string()
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/for_any_all.py | pylint/extensions/for_any_all.py | 53 | as_string | ref | function | loop_iter = node.iter.as_string()
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/for_any_all.py | pylint/extensions/for_any_all.py | 54 | get_children | ref | function | test_node = next(node.body[0].get_children())
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/for_any_all.py | pylint/extensions/for_any_all.py | 63 | as_string | ref | function | test = test_node.as_string()
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/for_any_all.py | pylint/extensions/for_any_all.py | 67 | register | def | function | def register(linter: "PyLinter") -> None:
linter.register_checker(ConsiderUsingAnyOrAllChecker(linter))
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/for_any_all.py | pylint/extensions/for_any_all.py | 68 | register_checker | ref | function | linter.register_checker(ConsiderUsingAnyOrAllChecker(linter))
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/for_any_all.py | pylint/extensions/for_any_all.py | 68 | ConsiderUsingAnyOrAllChecker | ref | function | linter.register_checker(ConsiderUsingAnyOrAllChecker(linter))
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/mccabe.py | pylint/extensions/mccabe.py | 29 | PathGraph | def | class | __init__ |
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/mccabe.py | pylint/extensions/mccabe.py | 35 | PathGraphingAstVisitor | def | class | __init__ default dispatch visitFunctionDef visitSimpleStatement visitWith _append_node _subgraph _subgraph_parse |
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/mccabe.py | pylint/extensions/mccabe.py | 40 | default | def | function | def default(self, node, *args):
for child in node.get_children():
self.dispatch(child, *args)
def dispatch(self, node, *args):
self.node = node
klass = node.__class__
meth = self._cache.get(klass)
if meth is None:
class_name = klass.__name__
meth = getattr(self.visitor, "visit" + class_name, self.default)
self._cache[klass] = meth
return meth(node, *args)
def visitFunctionDef(self, node):
if self.graph is not None:
# closure
pathnode = self._append_node(node)
self.tail = pathnode
self.dispatch_list(node.body)
bottom = f"{self._bottom_counter}"
self._bottom_counter += 1
self.graph.connect(self.tail, bottom)
self.graph.connect(node, bottom)
self.tail = bottom
else:
self.graph = PathGraph(node)
self.tail = node
self.dispatch_list(node.body)
self.graphs[f"{self.classname}{node.name}"] = self.graph
self.reset()
visitAsyncFunctionDef = visitFunctionDef
def visitSimpleStatement(self, node):
self._append_node(node)
visitAssert = (
visitAssign
) = (
visitAugAssign
) = (
visitDelete
) = (
visitPrint
) = (
visitRaise
) = (
visitYield
) = (
visitImport
) = (
visitCall
) = (
visitSubscript
) = (
visitPass
) = (
visitContinue
) = (
visitBreak
) = visitGlobal = visitReturn = visitExpr = visitAwait = visitSimpleStatement
def visitWith(self, node):
self._append_node(node)
self.dispatch_list(node.body)
visitAsyncWith = visitWith
def _append_node(self, node):
if not self.tail:
return None
self.graph.connect(self.tail, node)
self.tail = node
return node
def _subgraph(self, node, name, extra_blocks=()):
"""Create the subgraphs representing any `if` and `for` statements."""
if self.graph is None:
# global loop
self.graph = PathGraph(node)
self._subgraph_parse(node, node, extra_blocks)
self.graphs[f"{self.classname}{name}"] = self.graph
self.reset()
else:
self._append_node(node)
self._subgraph_parse(node, node, extra_blocks)
def _subgraph_parse(self, node, pathnode, extra_blocks):
"""Parse the body and any `else` block of `if` and `for` statements."""
loose_ends = []
self.tail = node
self.dispatch_list(node.body)
loose_ends.append(self.tail)
for extra in extra_blocks:
self.tail = node
self.dispatch_list(extra.body)
loose_ends.append(self.tail)
if node.orelse:
self.tail = node
self.dispatch_list(node.orelse)
loose_ends.append(self.tail)
else:
loose_ends.append(node)
if node:
bottom = f"{self._bottom_counter}"
self._bottom_counter += 1
for end in loose_ends:
self.graph.connect(end, bottom)
self.tail = bottom
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/mccabe.py | pylint/extensions/mccabe.py | 41 | get_children | ref | function | for child in node.get_children():
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/mccabe.py | pylint/extensions/mccabe.py | 42 | dispatch | ref | function | self.dispatch(child, *args)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/mccabe.py | pylint/extensions/mccabe.py | 44 | dispatch | def | function | def dispatch(self, node, *args):
self.node = node
klass = node.__class__
meth = self._cache.get(klass)
if meth is None:
class_name = klass.__name__
meth = getattr(self.visitor, "visit" + class_name, self.default)
self._cache[klass] = meth
return meth(node, *args)
def visitFunctionDef(self, node):
if self.graph is not None:
# closure
pathnode = self._append_node(node)
self.tail = pathnode
self.dispatch_list(node.body)
bottom = f"{self._bottom_counter}"
self._bottom_counter += 1
self.graph.connect(self.tail, bottom)
self.graph.connect(node, bottom)
self.tail = bottom
else:
self.graph = PathGraph(node)
self.tail = node
self.dispatch_list(node.body)
self.graphs[f"{self.classname}{node.name}"] = self.graph
self.reset()
visitAsyncFunctionDef = visitFunctionDef
def visitSimpleStatement(self, node):
self._append_node(node)
visitAssert = (
visitAssign
) = (
visitAugAssign
) = (
visitDelete
) = (
visitPrint
) = (
visitRaise
) = (
visitYield
) = (
visitImport
) = (
visitCall
) = (
visitSubscript
) = (
visitPass
) = (
visitContinue
) = (
visitBreak
) = visitGlobal = visitReturn = visitExpr = visitAwait = visitSimpleStatement
def visitWith(self, node):
self._append_node(node)
self.dispatch_list(node.body)
visitAsyncWith = visitWith
def _append_node(self, node):
if not self.tail:
return None
self.graph.connect(self.tail, node)
self.tail = node
return node
def _subgraph(self, node, name, extra_blocks=()):
"""Create the subgraphs representing any `if` and `for` statements."""
if self.graph is None:
# global loop
self.graph = PathGraph(node)
self._subgraph_parse(node, node, extra_blocks)
self.graphs[f"{self.classname}{name}"] = self.graph
self.reset()
else:
self._append_node(node)
self._subgraph_parse(node, node, extra_blocks)
def _subgraph_parse(self, node, pathnode, extra_blocks):
"""Parse the body and any `else` block of `if` and `for` statements."""
loose_ends = []
self.tail = node
self.dispatch_list(node.body)
loose_ends.append(self.tail)
for extra in extra_blocks:
self.tail = node
self.dispatch_list(extra.body)
loose_ends.append(self.tail)
if node.orelse:
self.tail = node
self.dispatch_list(node.orelse)
loose_ends.append(self.tail)
else:
loose_ends.append(node)
if node:
bottom = f"{self._bottom_counter}"
self._bottom_counter += 1
for end in loose_ends:
self.graph.connect(end, bottom)
self.tail = bottom
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/mccabe.py | pylint/extensions/mccabe.py | 52 | meth | ref | function | return meth(node, *args)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/mccabe.py | pylint/extensions/mccabe.py | 54 | visitFunctionDef | def | function | def visitFunctionDef(self, node):
if self.graph is not None:
# closure
pathnode = self._append_node(node)
self.tail = pathnode
self.dispatch_list(node.body)
bottom = f"{self._bottom_counter}"
self._bottom_counter += 1
self.graph.connect(self.tail, bottom)
self.graph.connect(node, bottom)
self.tail = bottom
else:
self.graph = PathGraph(node)
self.tail = node
self.dispatch_list(node.body)
self.graphs[f"{self.classname}{node.name}"] = self.graph
self.reset()
visitAsyncFunctionDef = visitFunctionDef
def visitSimpleStatement(self, node):
self._append_node(node)
visitAssert = (
visitAssign
) = (
visitAugAssign
) = (
visitDelete
) = (
visitPrint
) = (
visitRaise
) = (
visitYield
) = (
visitImport
) = (
visitCall
) = (
visitSubscript
) = (
visitPass
) = (
visitContinue
) = (
visitBreak
) = visitGlobal = visitReturn = visitExpr = visitAwait = visitSimpleStatement
def visitWith(self, node):
self._append_node(node)
self.dispatch_list(node.body)
visitAsyncWith = visitWith
def _append_node(self, node):
if not self.tail:
return None
self.graph.connect(self.tail, node)
self.tail = node
return node
def _subgraph(self, node, name, extra_blocks=()):
"""Create the subgraphs representing any `if` and `for` statements."""
if self.graph is None:
# global loop
self.graph = PathGraph(node)
self._subgraph_parse(node, node, extra_blocks)
self.graphs[f"{self.classname}{name}"] = self.graph
self.reset()
else:
self._append_node(node)
self._subgraph_parse(node, node, extra_blocks)
def _subgraph_parse(self, node, pathnode, extra_blocks):
"""Parse the body and any `else` block of `if` and `for` statements."""
loose_ends = []
self.tail = node
self.dispatch_list(node.body)
loose_ends.append(self.tail)
for extra in extra_blocks:
self.tail = node
self.dispatch_list(extra.body)
loose_ends.append(self.tail)
if node.orelse:
self.tail = node
self.dispatch_list(node.orelse)
loose_ends.append(self.tail)
else:
loose_ends.append(node)
if node:
bottom = f"{self._bottom_counter}"
self._bottom_counter += 1
for end in loose_ends:
self.graph.connect(end, bottom)
self.tail = bottom
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/mccabe.py | pylint/extensions/mccabe.py | 57 | _append_node | ref | function | pathnode = self._append_node(node)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/mccabe.py | pylint/extensions/mccabe.py | 59 | dispatch_list | ref | function | self.dispatch_list(node.body)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/mccabe.py | pylint/extensions/mccabe.py | 62 | connect | ref | function | self.graph.connect(self.tail, bottom)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/mccabe.py | pylint/extensions/mccabe.py | 63 | connect | ref | function | self.graph.connect(node, bottom)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/mccabe.py | pylint/extensions/mccabe.py | 66 | PathGraph | ref | function | self.graph = PathGraph(node)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/mccabe.py | pylint/extensions/mccabe.py | 68 | dispatch_list | ref | function | self.dispatch_list(node.body)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/mccabe.py | pylint/extensions/mccabe.py | 70 | reset | ref | function | self.reset()
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/mccabe.py | pylint/extensions/mccabe.py | 74 | visitSimpleStatement | def | function | def visitSimpleStatement(self, node):
self._append_node(node)
visitAssert = (
visitAssign
) = (
visitAugAssign
) = (
visitDelete
) = (
visitPrint
) = (
visitRaise
) = (
visitYield
) = (
visitImport
) = (
visitCall
) = (
visitSubscript
) = (
visitPass
) = (
visitContinue
) = (
visitBreak
) = visitGlobal = visitReturn = visitExpr = visitAwait = visitSimpleStatement
def visitWith(self, node):
self._append_node(node)
self.dispatch_list(node.body)
visitAsyncWith = visitWith
def _append_node(self, node):
if not self.tail:
return None
self.graph.connect(self.tail, node)
self.tail = node
return node
def _subgraph(self, node, name, extra_blocks=()):
"""Create the subgraphs representing any `if` and `for` statements."""
if self.graph is None:
# global loop
self.graph = PathGraph(node)
self._subgraph_parse(node, node, extra_blocks)
self.graphs[f"{self.classname}{name}"] = self.graph
self.reset()
else:
self._append_node(node)
self._subgraph_parse(node, node, extra_blocks)
def _subgraph_parse(self, node, pathnode, extra_blocks):
"""Parse the body and any `else` block of `if` and `for` statements."""
loose_ends = []
self.tail = node
self.dispatch_list(node.body)
loose_ends.append(self.tail)
for extra in extra_blocks:
self.tail = node
self.dispatch_list(extra.body)
loose_ends.append(self.tail)
if node.orelse:
self.tail = node
self.dispatch_list(node.orelse)
loose_ends.append(self.tail)
else:
loose_ends.append(node)
if node:
bottom = f"{self._bottom_counter}"
self._bottom_counter += 1
for end in loose_ends:
self.graph.connect(end, bottom)
self.tail = bottom
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/mccabe.py | pylint/extensions/mccabe.py | 75 | _append_node | ref | function | self._append_node(node)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/mccabe.py | pylint/extensions/mccabe.py | 103 | visitWith | def | function | def visitWith(self, node):
self._append_node(node)
self.dispatch_list(node.body)
visitAsyncWith = visitWith
def _append_node(self, node):
if not self.tail:
return None
self.graph.connect(self.tail, node)
self.tail = node
return node
def _subgraph(self, node, name, extra_blocks=()):
"""Create the subgraphs representing any `if` and `for` statements."""
if self.graph is None:
# global loop
self.graph = PathGraph(node)
self._subgraph_parse(node, node, extra_blocks)
self.graphs[f"{self.classname}{name}"] = self.graph
self.reset()
else:
self._append_node(node)
self._subgraph_parse(node, node, extra_blocks)
def _subgraph_parse(self, node, pathnode, extra_blocks):
"""Parse the body and any `else` block of `if` and `for` statements."""
loose_ends = []
self.tail = node
self.dispatch_list(node.body)
loose_ends.append(self.tail)
for extra in extra_blocks:
self.tail = node
self.dispatch_list(extra.body)
loose_ends.append(self.tail)
if node.orelse:
self.tail = node
self.dispatch_list(node.orelse)
loose_ends.append(self.tail)
else:
loose_ends.append(node)
if node:
bottom = f"{self._bottom_counter}"
self._bottom_counter += 1
for end in loose_ends:
self.graph.connect(end, bottom)
self.tail = bottom
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/mccabe.py | pylint/extensions/mccabe.py | 104 | _append_node | ref | function | self._append_node(node)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/mccabe.py | pylint/extensions/mccabe.py | 105 | dispatch_list | ref | function | self.dispatch_list(node.body)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/mccabe.py | pylint/extensions/mccabe.py | 109 | _append_node | def | function | def _append_node(self, node):
if not self.tail:
return None
self.graph.connect(self.tail, node)
self.tail = node
return node
def _subgraph(self, node, name, extra_blocks=()):
"""Create the subgraphs representing any `if` and `for` statements."""
if self.graph is None:
# global loop
self.graph = PathGraph(node)
self._subgraph_parse(node, node, extra_blocks)
self.graphs[f"{self.classname}{name}"] = self.graph
self.reset()
else:
self._append_node(node)
self._subgraph_parse(node, node, extra_blocks)
def _subgraph_parse(self, node, pathnode, extra_blocks):
"""Parse the body and any `else` block of `if` and `for` statements."""
loose_ends = []
self.tail = node
self.dispatch_list(node.body)
loose_ends.append(self.tail)
for extra in extra_blocks:
self.tail = node
self.dispatch_list(extra.body)
loose_ends.append(self.tail)
if node.orelse:
self.tail = node
self.dispatch_list(node.orelse)
loose_ends.append(self.tail)
else:
loose_ends.append(node)
if node:
bottom = f"{self._bottom_counter}"
self._bottom_counter += 1
for end in loose_ends:
self.graph.connect(end, bottom)
self.tail = bottom
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/mccabe.py | pylint/extensions/mccabe.py | 112 | connect | ref | function | self.graph.connect(self.tail, node)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/mccabe.py | pylint/extensions/mccabe.py | 116 | _subgraph | def | function | def _subgraph(self, node, name, extra_blocks=()):
"""Create the subgraphs representing any `if` and `for` statements."""
if self.graph is None:
# global loop
self.graph = PathGraph(node)
self._subgraph_parse(node, node, extra_blocks)
self.graphs[f"{self.classname}{name}"] = self.graph
self.reset()
else:
self._append_node(node)
self._subgraph_parse(node, node, extra_blocks)
def _subgraph_parse(self, node, pathnode, extra_blocks):
"""Parse the body and any `else` block of `if` and `for` statements."""
loose_ends = []
self.tail = node
self.dispatch_list(node.body)
loose_ends.append(self.tail)
for extra in extra_blocks:
self.tail = node
self.dispatch_list(extra.body)
loose_ends.append(self.tail)
if node.orelse:
self.tail = node
self.dispatch_list(node.orelse)
loose_ends.append(self.tail)
else:
loose_ends.append(node)
if node:
bottom = f"{self._bottom_counter}"
self._bottom_counter += 1
for end in loose_ends:
self.graph.connect(end, bottom)
self.tail = bottom
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/mccabe.py | pylint/extensions/mccabe.py | 120 | PathGraph | ref | function | self.graph = PathGraph(node)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/mccabe.py | pylint/extensions/mccabe.py | 121 | _subgraph_parse | ref | function | self._subgraph_parse(node, node, extra_blocks)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/mccabe.py | pylint/extensions/mccabe.py | 123 | reset | ref | function | self.reset()
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/mccabe.py | pylint/extensions/mccabe.py | 125 | _append_node | ref | function | self._append_node(node)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/mccabe.py | pylint/extensions/mccabe.py | 126 | _subgraph_parse | ref | function | self._subgraph_parse(node, node, extra_blocks)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/mccabe.py | pylint/extensions/mccabe.py | 128 | _subgraph_parse | def | function | def _subgraph_parse(self, node, pathnode, extra_blocks):
"""Parse the body and any `else` block of `if` and `for` statements."""
loose_ends = []
self.tail = node
self.dispatch_list(node.body)
loose_ends.append(self.tail)
for extra in extra_blocks:
self.tail = node
self.dispatch_list(extra.body)
loose_ends.append(self.tail)
if node.orelse:
self.tail = node
self.dispatch_list(node.orelse)
loose_ends.append(self.tail)
else:
loose_ends.append(node)
if node:
bottom = f"{self._bottom_counter}"
self._bottom_counter += 1
for end in loose_ends:
self.graph.connect(end, bottom)
self.tail = bottom
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/mccabe.py | pylint/extensions/mccabe.py | 132 | dispatch_list | ref | function | self.dispatch_list(node.body)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/mccabe.py | pylint/extensions/mccabe.py | 136 | dispatch_list | ref | function | self.dispatch_list(extra.body)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/mccabe.py | pylint/extensions/mccabe.py | 140 | dispatch_list | ref | function | self.dispatch_list(node.orelse)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/mccabe.py | pylint/extensions/mccabe.py | 148 | connect | ref | function | self.graph.connect(end, bottom)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/mccabe.py | pylint/extensions/mccabe.py | 152 | McCabeMethodChecker | def | class | visit_module |
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/mccabe.py | pylint/extensions/mccabe.py | 180 | check_messages | ref | function | @check_messages("too-complex")
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/mccabe.py | pylint/extensions/mccabe.py | 181 | visit_module | def | function | def visit_module(self, node: nodes.Module) -> None:
"""Visit an astroid.Module node to check too complex rating and
add message if is greater than max_complexity stored from options
"""
visitor = PathGraphingAstVisitor()
for child in node.body:
visitor.preorder(child, visitor)
for graph in visitor.graphs.values():
complexity = graph.complexity()
node = graph.root
if hasattr(node, "name"):
node_name = f"'{node.name}'"
else:
node_name = f"This '{node.__class__.__name__.lower()}'"
if complexity <= self.config.max_complexity:
continue
self.add_message(
"too-complex", node=node, confidence=HIGH, args=(node_name, complexity)
)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/mccabe.py | pylint/extensions/mccabe.py | 185 | PathGraphingAstVisitor | ref | function | visitor = PathGraphingAstVisitor()
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/mccabe.py | pylint/extensions/mccabe.py | 187 | preorder | ref | function | visitor.preorder(child, visitor)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/mccabe.py | pylint/extensions/mccabe.py | 189 | complexity | ref | function | complexity = graph.complexity()
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/mccabe.py | pylint/extensions/mccabe.py | 197 | add_message | ref | function | self.add_message(
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/mccabe.py | pylint/extensions/mccabe.py | 202 | register | def | function | def register(linter: "PyLinter") -> None:
linter.register_checker(McCabeMethodChecker(linter))
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/mccabe.py | pylint/extensions/mccabe.py | 203 | register_checker | ref | function | linter.register_checker(McCabeMethodChecker(linter))
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/mccabe.py | pylint/extensions/mccabe.py | 203 | McCabeMethodChecker | ref | function | linter.register_checker(McCabeMethodChecker(linter))
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/overlapping_exceptions.py | pylint/extensions/overlapping_exceptions.py | 18 | OverlappingExceptionsChecker | def | class | visit_tryexcept |
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/overlapping_exceptions.py | pylint/extensions/overlapping_exceptions.py | 37 | check_messages | ref | function | @utils.check_messages("overlapping-except")
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/overlapping_exceptions.py | pylint/extensions/overlapping_exceptions.py | 38 | visit_tryexcept | def | function | def visit_tryexcept(self, node: nodes.TryExcept) -> None:
"""Check for empty except."""
for handler in node.handlers:
if handler.type is None:
continue
if isinstance(handler.type, astroid.BoolOp):
continue
try:
excs = list(_annotated_unpack_infer(handler.type))
except astroid.InferenceError:
continue
handled_in_clause: List[Tuple[Any, Any]] = []
for part, exc in excs:
if exc is astroid.Uninferable:
continue
if isinstance(exc, astroid.Instance) and utils.inherit_from_std_ex(exc):
exc = exc._proxied
if not isinstance(exc, astroid.ClassDef):
continue
exc_ancestors = [
anc for anc in exc.ancestors() if isinstance(anc, astroid.ClassDef)
]
for prev_part, prev_exc in handled_in_clause:
prev_exc_ancestors = [
anc
for anc in prev_exc.ancestors()
if isinstance(anc, astroid.ClassDef)
]
if exc == prev_exc:
self.add_message(
"overlapping-except",
node=handler.type,
args=f"{prev_part.as_string()} and {part.as_string()} are the same",
)
elif prev_exc in exc_ancestors or exc in prev_exc_ancestors:
ancestor = part if exc in prev_exc_ancestors else prev_part
descendant = part if prev_exc in exc_ancestors else prev_part
self.add_message(
"overlapping-except",
node=handler.type,
args=f"{ancestor.as_string()} is an ancestor class of {descendant.as_string()}",
)
handled_in_clause += [(part, exc)]
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/overlapping_exceptions.py | pylint/extensions/overlapping_exceptions.py | 46 | _annotated_unpack_infer | ref | function | excs = list(_annotated_unpack_infer(handler.type))
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/extensions/overlapping_exceptions.py | pylint/extensions/overlapping_exceptions.py | 54 | inherit_from_std_ex | ref | function | if isinstance(exc, astroid.Instance) and utils.inherit_from_std_ex(exc):
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.