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/logging.py | pylint/checkers/logging.py | 204 | is_logging_name | def | function | def is_logging_name():
return (
isinstance(node.func, nodes.Attribute)
and isinstance(node.func.expr, nodes.Name)
and node.func.expr.name in self._logging_names
)
def is_logger_class():
for inferred in infer_all(node.func):
if isinstance(inferred, astroid.BoundMethod):
parent = inferred._proxied.parent
if isinstance(parent, nodes.ClassDef) and (
parent.qname() == "logging.Logger"
or any(
ancestor.qname() == "logging.Logger"
for ancestor in parent.ancestors()
)
):
return _True, inferred._proxied.name
return _False, None
if is_logging_name():
name = node.func.attrname
else:
result, name = is_logger_class()
if not result:
return
self._check_log_method(node, name)
def _check_log_method(self, node, name):
"""Checks calls to logging.log(level, format, *format_args)."""
if name == "log":
if node.starargs or node.kwargs or len(node.args) < 2:
# Either a malformed call, star args, or double-star args. Beyond
# the scope of this checker.
return
format_pos = 1
elif name in CHECKED_CONVENIENCE_FUNCTIONS:
if node.starargs or node.kwargs or not node.args:
# Either no args, star args, or double-star args. Beyond the
# scope of this checker.
return
format_pos = 0
else:
return
if isinstance(node.args[format_pos], nodes.BinOp):
binop = node.args[format_pos]
emit = binop.op == "%"
if binop.op == "+":
total_number_of_strings = sum(
1
for operand in (binop.left, binop.right)
if self._is_operand_literal_str(utils.safe_infer(operand))
)
emit = total_number_of_strings > 0
if emit:
self.add_message(
"logging-not-lazy",
node=node,
args=(self._helper_string(node),),
)
elif isinstance(node.args[format_pos], nodes.Call):
self._check_call_func(node.args[format_pos])
elif isinstance(node.args[format_pos], nodes.Const):
self._check_format_string(node, format_pos)
elif isinstance(node.args[format_pos], nodes.JoinedStr):
self.add_message(
"logging-fstring-interpolation",
node=node,
args=(self._helper_string(node),),
)
def _helper_string(self, node):
"""Create a string that lists the valid types of formatting for this node."""
valid_types = ["lazy %"]
if not self.linter.is_message_enabled(
"logging-fstring-formatting", node.fromlineno
):
valid_types.append("fstring")
if not self.linter.is_message_enabled(
"logging-format-interpolation", node.fromlineno
):
valid_types.append(".format()")
if not self.linter.is_message_enabled("logging-not-lazy", node.fromlineno):
valid_types.append("%")
return " or ".join(valid_types)
@staticmethod
def _is_operand_literal_str(operand):
"""Return _True if the operand in argument is a literal string."""
return isinstance(operand, nodes.Const) and operand.name == "str"
def _check_call_func(self, node: nodes.Call):
"""Checks that function call is not format_string.format()."""
func = utils.safe_infer(node.func)
types = ("str", "unicode")
methods = ("format",)
if (
isinstance(func, astroid.BoundMethod)
and is_method_call(func, types, methods)
and not is_complex_format_str(func.bound)
):
self.add_message(
"logging-format-interpolation",
node=node,
args=(self._helper_string(node),),
)
def _check_format_string(self, node, format_arg):
"""Checks that format string tokens match the supplied arguments.
Args:
node (nodes.NodeNG): AST node to be checked.
format_arg (int): Index of the format string in the node arguments.
"""
num_args = _count_supplied_tokens(node.args[format_arg + 1 :])
if not num_args:
# If no args were supplied the string is not interpolated and can contain
# formatting characters - it's used verbatim. Don't check any further.
return
format_string = node.args[format_arg].value
required_num_args = 0
if isinstance(format_string, bytes):
format_string = format_string.decode()
if isinstance(format_string, str):
try:
if self._format_style == "old":
keyword_args, required_num_args, _, _ = utils.parse_format_string(
format_string
)
if keyword_args:
# Keyword checking on logging strings is complicated by
# special keywords - out of scope.
return
elif self._format_style == "new":
(
keyword_arguments,
implicit_pos_args,
explicit_pos_args,
) = utils.parse_format_method_string(format_string)
keyword_args_cnt = len(
{k for k, l in keyword_arguments if not isinstance(k, int)}
)
required_num_args = (
keyword_args_cnt + implicit_pos_args + explicit_pos_args
)
except utils.UnsupportedFormatCharacter as ex:
char = format_string[ex.index]
self.add_message(
"logging-unsupported-format",
node=node,
args=(char, ord(char), ex.index),
)
return
except utils.IncompleteFormatString:
self.add_message("logging-format-truncated", node=node)
return
if num_args > required_num_args:
self.add_message("logging-too-many-args", node=node)
elif num_args < required_num_args:
self.add_message("logging-too-few-args", node=node)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/logging.py | pylint/checkers/logging.py | 211 | is_logger_class | def | class | |
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/logging.py | pylint/checkers/logging.py | 212 | infer_all | ref | function | for inferred in infer_all(node.func):
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/logging.py | pylint/checkers/logging.py | 216 | qname | ref | function | parent.qname() == "logging.Logger"
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/logging.py | pylint/checkers/logging.py | 218 | qname | ref | function | ancestor.qname() == "logging.Logger"
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/logging.py | pylint/checkers/logging.py | 219 | ancestors | ref | function | for ancestor in parent.ancestors()
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/logging.py | pylint/checkers/logging.py | 225 | is_logging_name | ref | function | if is_logging_name():
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/logging.py | pylint/checkers/logging.py | 228 | is_logger_class | ref | class | |
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/logging.py | pylint/checkers/logging.py | 231 | _check_log_method | ref | function | self._check_log_method(node, name)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/logging.py | pylint/checkers/logging.py | 233 | _check_log_method | def | function | def _check_log_method(self, node, name):
"""Checks calls to logging.log(level, format, *format_args)."""
if name == "log":
if node.starargs or node.kwargs or len(node.args) < 2:
# Either a malformed call, star args, or double-star args. Beyond
# the scope of this checker.
return
format_pos = 1
elif name in CHECKED_CONVENIENCE_FUNCTIONS:
if node.starargs or node.kwargs or not node.args:
# Either no args, star args, or double-star args. Beyond the
# scope of this checker.
return
format_pos = 0
else:
return
if isinstance(node.args[format_pos], nodes.BinOp):
binop = node.args[format_pos]
emit = binop.op == "%"
if binop.op == "+":
total_number_of_strings = sum(
1
for operand in (binop.left, binop.right)
if self._is_operand_literal_str(utils.safe_infer(operand))
)
emit = total_number_of_strings > 0
if emit:
self.add_message(
"logging-not-lazy",
node=node,
args=(self._helper_string(node),),
)
elif isinstance(node.args[format_pos], nodes.Call):
self._check_call_func(node.args[format_pos])
elif isinstance(node.args[format_pos], nodes.Const):
self._check_format_string(node, format_pos)
elif isinstance(node.args[format_pos], nodes.JoinedStr):
self.add_message(
"logging-fstring-interpolation",
node=node,
args=(self._helper_string(node),),
)
def _helper_string(self, node):
"""Create a string that lists the valid types of formatting for this node."""
valid_types = ["lazy %"]
if not self.linter.is_message_enabled(
"logging-fstring-formatting", node.fromlineno
):
valid_types.append("fstring")
if not self.linter.is_message_enabled(
"logging-format-interpolation", node.fromlineno
):
valid_types.append(".format()")
if not self.linter.is_message_enabled("logging-not-lazy", node.fromlineno):
valid_types.append("%")
return " or ".join(valid_types)
@staticmethod
def _is_operand_literal_str(operand):
"""Return _True if the operand in argument is a literal string."""
return isinstance(operand, nodes.Const) and operand.name == "str"
def _check_call_func(self, node: nodes.Call):
"""Checks that function call is not format_string.format()."""
func = utils.safe_infer(node.func)
types = ("str", "unicode")
methods = ("format",)
if (
isinstance(func, astroid.BoundMethod)
and is_method_call(func, types, methods)
and not is_complex_format_str(func.bound)
):
self.add_message(
"logging-format-interpolation",
node=node,
args=(self._helper_string(node),),
)
def _check_format_string(self, node, format_arg):
"""Checks that format string tokens match the supplied arguments.
Args:
node (nodes.NodeNG): AST node to be checked.
format_arg (int): Index of the format string in the node arguments.
"""
num_args = _count_supplied_tokens(node.args[format_arg + 1 :])
if not num_args:
# If no args were supplied the string is not interpolated and can contain
# formatting characters - it's used verbatim. Don't check any further.
return
format_string = node.args[format_arg].value
required_num_args = 0
if isinstance(format_string, bytes):
format_string = format_string.decode()
if isinstance(format_string, str):
try:
if self._format_style == "old":
keyword_args, required_num_args, _, _ = utils.parse_format_string(
format_string
)
if keyword_args:
# Keyword checking on logging strings is complicated by
# special keywords - out of scope.
return
elif self._format_style == "new":
(
keyword_arguments,
implicit_pos_args,
explicit_pos_args,
) = utils.parse_format_method_string(format_string)
keyword_args_cnt = len(
{k for k, l in keyword_arguments if not isinstance(k, int)}
)
required_num_args = (
keyword_args_cnt + implicit_pos_args + explicit_pos_args
)
except utils.UnsupportedFormatCharacter as ex:
char = format_string[ex.index]
self.add_message(
"logging-unsupported-format",
node=node,
args=(char, ord(char), ex.index),
)
return
except utils.IncompleteFormatString:
self.add_message("logging-format-truncated", node=node)
return
if num_args > required_num_args:
self.add_message("logging-too-many-args", node=node)
elif num_args < required_num_args:
self.add_message("logging-too-few-args", node=node)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/logging.py | pylint/checkers/logging.py | 257 | _is_operand_literal_str | ref | function | if self._is_operand_literal_str(utils.safe_infer(operand))
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/logging.py | pylint/checkers/logging.py | 257 | safe_infer | ref | function | if self._is_operand_literal_str(utils.safe_infer(operand))
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/logging.py | pylint/checkers/logging.py | 261 | add_message | ref | function | self.add_message(
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/logging.py | pylint/checkers/logging.py | 264 | _helper_string | ref | function | args=(self._helper_string(node),),
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/logging.py | pylint/checkers/logging.py | 267 | _check_call_func | ref | function | self._check_call_func(node.args[format_pos])
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/logging.py | pylint/checkers/logging.py | 269 | _check_format_string | ref | function | self._check_format_string(node, format_pos)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/logging.py | pylint/checkers/logging.py | 271 | add_message | ref | function | self.add_message(
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/logging.py | pylint/checkers/logging.py | 274 | _helper_string | ref | function | args=(self._helper_string(node),),
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/logging.py | pylint/checkers/logging.py | 277 | _helper_string | def | function | def _helper_string(self, node):
"""Create a string that lists the valid types of formatting for this node."""
valid_types = ["lazy %"]
if not self.linter.is_message_enabled(
"logging-fstring-formatting", node.fromlineno
):
valid_types.append("fstring")
if not self.linter.is_message_enabled(
"logging-format-interpolation", node.fromlineno
):
valid_types.append(".format()")
if not self.linter.is_message_enabled("logging-not-lazy", node.fromlineno):
valid_types.append("%")
return " or ".join(valid_types)
@staticmethod
def _is_operand_literal_str(operand):
"""Return _True if the operand in argument is a literal string."""
return isinstance(operand, nodes.Const) and operand.name == "str"
def _check_call_func(self, node: nodes.Call):
"""Checks that function call is not format_string.format()."""
func = utils.safe_infer(node.func)
types = ("str", "unicode")
methods = ("format",)
if (
isinstance(func, astroid.BoundMethod)
and is_method_call(func, types, methods)
and not is_complex_format_str(func.bound)
):
self.add_message(
"logging-format-interpolation",
node=node,
args=(self._helper_string(node),),
)
def _check_format_string(self, node, format_arg):
"""Checks that format string tokens match the supplied arguments.
Args:
node (nodes.NodeNG): AST node to be checked.
format_arg (int): Index of the format string in the node arguments.
"""
num_args = _count_supplied_tokens(node.args[format_arg + 1 :])
if not num_args:
# If no args were supplied the string is not interpolated and can contain
# formatting characters - it's used verbatim. Don't check any further.
return
format_string = node.args[format_arg].value
required_num_args = 0
if isinstance(format_string, bytes):
format_string = format_string.decode()
if isinstance(format_string, str):
try:
if self._format_style == "old":
keyword_args, required_num_args, _, _ = utils.parse_format_string(
format_string
)
if keyword_args:
# Keyword checking on logging strings is complicated by
# special keywords - out of scope.
return
elif self._format_style == "new":
(
keyword_arguments,
implicit_pos_args,
explicit_pos_args,
) = utils.parse_format_method_string(format_string)
keyword_args_cnt = len(
{k for k, l in keyword_arguments if not isinstance(k, int)}
)
required_num_args = (
keyword_args_cnt + implicit_pos_args + explicit_pos_args
)
except utils.UnsupportedFormatCharacter as ex:
char = format_string[ex.index]
self.add_message(
"logging-unsupported-format",
node=node,
args=(char, ord(char), ex.index),
)
return
except utils.IncompleteFormatString:
self.add_message("logging-format-truncated", node=node)
return
if num_args > required_num_args:
self.add_message("logging-too-many-args", node=node)
elif num_args < required_num_args:
self.add_message("logging-too-few-args", node=node)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/logging.py | pylint/checkers/logging.py | 281 | is_message_enabled | ref | function | if not self.linter.is_message_enabled(
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/logging.py | pylint/checkers/logging.py | 285 | is_message_enabled | ref | function | if not self.linter.is_message_enabled(
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/logging.py | pylint/checkers/logging.py | 289 | is_message_enabled | ref | function | if not self.linter.is_message_enabled("logging-not-lazy", node.fromlineno):
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/logging.py | pylint/checkers/logging.py | 295 | _is_operand_literal_str | def | function | def _is_operand_literal_str(operand):
"""Return _True if the operand in argument is a literal string."""
return isinstance(operand, nodes.Const) and operand.name == "str"
def _check_call_func(self, node: nodes.Call):
"""Checks that function call is not format_string.format()."""
func = utils.safe_infer(node.func)
types = ("str", "unicode")
methods = ("format",)
if (
isinstance(func, astroid.BoundMethod)
and is_method_call(func, types, methods)
and not is_complex_format_str(func.bound)
):
self.add_message(
"logging-format-interpolation",
node=node,
args=(self._helper_string(node),),
)
def _check_format_string(self, node, format_arg):
"""Checks that format string tokens match the supplied arguments.
Args:
node (nodes.NodeNG): AST node to be checked.
format_arg (int): Index of the format string in the node arguments.
"""
num_args = _count_supplied_tokens(node.args[format_arg + 1 :])
if not num_args:
# If no args were supplied the string is not interpolated and can contain
# formatting characters - it's used verbatim. Don't check any further.
return
format_string = node.args[format_arg].value
required_num_args = 0
if isinstance(format_string, bytes):
format_string = format_string.decode()
if isinstance(format_string, str):
try:
if self._format_style == "old":
keyword_args, required_num_args, _, _ = utils.parse_format_string(
format_string
)
if keyword_args:
# Keyword checking on logging strings is complicated by
# special keywords - out of scope.
return
elif self._format_style == "new":
(
keyword_arguments,
implicit_pos_args,
explicit_pos_args,
) = utils.parse_format_method_string(format_string)
keyword_args_cnt = len(
{k for k, l in keyword_arguments if not isinstance(k, int)}
)
required_num_args = (
keyword_args_cnt + implicit_pos_args + explicit_pos_args
)
except utils.UnsupportedFormatCharacter as ex:
char = format_string[ex.index]
self.add_message(
"logging-unsupported-format",
node=node,
args=(char, ord(char), ex.index),
)
return
except utils.IncompleteFormatString:
self.add_message("logging-format-truncated", node=node)
return
if num_args > required_num_args:
self.add_message("logging-too-many-args", node=node)
elif num_args < required_num_args:
self.add_message("logging-too-few-args", node=node)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/logging.py | pylint/checkers/logging.py | 299 | _check_call_func | def | function | def _check_call_func(self, node: nodes.Call):
"""Checks that function call is not format_string.format()."""
func = utils.safe_infer(node.func)
types = ("str", "unicode")
methods = ("format",)
if (
isinstance(func, astroid.BoundMethod)
and is_method_call(func, types, methods)
and not is_complex_format_str(func.bound)
):
self.add_message(
"logging-format-interpolation",
node=node,
args=(self._helper_string(node),),
)
def _check_format_string(self, node, format_arg):
"""Checks that format string tokens match the supplied arguments.
Args:
node (nodes.NodeNG): AST node to be checked.
format_arg (int): Index of the format string in the node arguments.
"""
num_args = _count_supplied_tokens(node.args[format_arg + 1 :])
if not num_args:
# If no args were supplied the string is not interpolated and can contain
# formatting characters - it's used verbatim. Don't check any further.
return
format_string = node.args[format_arg].value
required_num_args = 0
if isinstance(format_string, bytes):
format_string = format_string.decode()
if isinstance(format_string, str):
try:
if self._format_style == "old":
keyword_args, required_num_args, _, _ = utils.parse_format_string(
format_string
)
if keyword_args:
# Keyword checking on logging strings is complicated by
# special keywords - out of scope.
return
elif self._format_style == "new":
(
keyword_arguments,
implicit_pos_args,
explicit_pos_args,
) = utils.parse_format_method_string(format_string)
keyword_args_cnt = len(
{k for k, l in keyword_arguments if not isinstance(k, int)}
)
required_num_args = (
keyword_args_cnt + implicit_pos_args + explicit_pos_args
)
except utils.UnsupportedFormatCharacter as ex:
char = format_string[ex.index]
self.add_message(
"logging-unsupported-format",
node=node,
args=(char, ord(char), ex.index),
)
return
except utils.IncompleteFormatString:
self.add_message("logging-format-truncated", node=node)
return
if num_args > required_num_args:
self.add_message("logging-too-many-args", node=node)
elif num_args < required_num_args:
self.add_message("logging-too-few-args", node=node)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/logging.py | pylint/checkers/logging.py | 301 | safe_infer | ref | function | func = utils.safe_infer(node.func)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/logging.py | pylint/checkers/logging.py | 306 | is_method_call | ref | function | and is_method_call(func, types, methods)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/logging.py | pylint/checkers/logging.py | 307 | is_complex_format_str | ref | function | and not is_complex_format_str(func.bound)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/logging.py | pylint/checkers/logging.py | 309 | add_message | ref | function | self.add_message(
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/logging.py | pylint/checkers/logging.py | 312 | _helper_string | ref | function | args=(self._helper_string(node),),
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/logging.py | pylint/checkers/logging.py | 315 | _check_format_string | def | function | def _check_format_string(self, node, format_arg):
"""Checks that format string tokens match the supplied arguments.
Args:
node (nodes.NodeNG): AST node to be checked.
format_arg (int): Index of the format string in the node arguments.
"""
num_args = _count_supplied_tokens(node.args[format_arg + 1 :])
if not num_args:
# If no args were supplied the string is not interpolated and can contain
# formatting characters - it's used verbatim. Don't check any further.
return
format_string = node.args[format_arg].value
required_num_args = 0
if isinstance(format_string, bytes):
format_string = format_string.decode()
if isinstance(format_string, str):
try:
if self._format_style == "old":
keyword_args, required_num_args, _, _ = utils.parse_format_string(
format_string
)
if keyword_args:
# Keyword checking on logging strings is complicated by
# special keywords - out of scope.
return
elif self._format_style == "new":
(
keyword_arguments,
implicit_pos_args,
explicit_pos_args,
) = utils.parse_format_method_string(format_string)
keyword_args_cnt = len(
{k for k, l in keyword_arguments if not isinstance(k, int)}
)
required_num_args = (
keyword_args_cnt + implicit_pos_args + explicit_pos_args
)
except utils.UnsupportedFormatCharacter as ex:
char = format_string[ex.index]
self.add_message(
"logging-unsupported-format",
node=node,
args=(char, ord(char), ex.index),
)
return
except utils.IncompleteFormatString:
self.add_message("logging-format-truncated", node=node)
return
if num_args > required_num_args:
self.add_message("logging-too-many-args", node=node)
elif num_args < required_num_args:
self.add_message("logging-too-few-args", node=node)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/logging.py | pylint/checkers/logging.py | 322 | _count_supplied_tokens | ref | function | num_args = _count_supplied_tokens(node.args[format_arg + 1 :])
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/logging.py | pylint/checkers/logging.py | 331 | decode | ref | function | format_string = format_string.decode()
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/logging.py | pylint/checkers/logging.py | 335 | parse_format_string | ref | function | keyword_args, required_num_args, _, _ = utils.parse_format_string(
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/logging.py | pylint/checkers/logging.py | 347 | parse_format_method_string | ref | function | ) = utils.parse_format_method_string(format_string)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/logging.py | pylint/checkers/logging.py | 357 | add_message | ref | function | self.add_message(
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/logging.py | pylint/checkers/logging.py | 364 | add_message | ref | function | self.add_message("logging-format-truncated", node=node)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/logging.py | pylint/checkers/logging.py | 367 | add_message | ref | function | self.add_message("logging-too-many-args", node=node)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/logging.py | pylint/checkers/logging.py | 369 | add_message | ref | function | self.add_message("logging-too-few-args", node=node)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/logging.py | pylint/checkers/logging.py | 372 | is_complex_format_str | def | function | def is_complex_format_str(node: nodes.NodeNG) -> bool:
"""Return whether the node represents a string with complex formatting specs."""
inferred = utils.safe_infer(node)
if inferred is None or not (
isinstance(inferred, nodes.Const) and isinstance(inferred.value, str)
):
return _True
try:
parsed = list(string.Formatter().parse(inferred.value))
except ValueError:
# This format string is invalid
return _False
return any(format_spec for (_, _, format_spec, _) in parsed)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/logging.py | pylint/checkers/logging.py | 374 | safe_infer | ref | function | inferred = utils.safe_infer(node)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/logging.py | pylint/checkers/logging.py | 380 | parse | ref | function | parsed = list(string.Formatter().parse(inferred.value))
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/logging.py | pylint/checkers/logging.py | 387 | _count_supplied_tokens | def | function | def _count_supplied_tokens(args):
"""Counts the number of tokens in an args list.
The Python log functions allow for special keyword arguments: func,
exc_info and extra. To handle these cases correctly, we only count
arguments that aren't keywords.
Args:
args (list): AST nodes that are arguments for a log format string.
Returns:
int: Number of AST nodes that aren't keywords.
"""
return sum(1 for arg in args if not isinstance(arg, nodes.Keyword))
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/logging.py | pylint/checkers/logging.py | 403 | register | def | function | def register(linter: "PyLinter") -> None:
linter.register_checker(LoggingChecker(linter))
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/logging.py | pylint/checkers/logging.py | 404 | register_checker | ref | function | linter.register_checker(LoggingChecker(linter))
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/logging.py | pylint/checkers/logging.py | 404 | LoggingChecker | ref | function | linter.register_checker(LoggingChecker(linter))
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/mapreduce_checker.py | pylint/checkers/mapreduce_checker.py | 9 | MapReduceMixin | def | class | get_map_data reduce_map_data |
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/mapreduce_checker.py | pylint/checkers/mapreduce_checker.py | 13 | get_map_data | def | function | def get_map_data(self):
"""Returns mergeable/reducible data that will be examined."""
@abc.abstractmethod
def reduce_map_data(self, linter, data):
"""For a given Checker, receives data for all mapped runs."""
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/mapreduce_checker.py | pylint/checkers/mapreduce_checker.py | 17 | reduce_map_data | def | function | def reduce_map_data(self, linter, data):
"""For a given Checker, receives data for all mapped runs."""
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/mapreduce_checker.py | pylint/checkers/mapreduce_checker.py | -1 | abc | ref | function | none |
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/mapreduce_checker.py | pylint/checkers/mapreduce_checker.py | -1 | MapReduceMixin | ref | function | none |
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/mapreduce_checker.py | pylint/checkers/mapreduce_checker.py | -1 | metaclass | ref | function | none |
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/mapreduce_checker.py | pylint/checkers/mapreduce_checker.py | -1 | abc | ref | function | none |
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/mapreduce_checker.py | pylint/checkers/mapreduce_checker.py | -1 | ABCMeta | ref | function | none |
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/mapreduce_checker.py | pylint/checkers/mapreduce_checker.py | -1 | @abc | ref | function | none |
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/mapreduce_checker.py | pylint/checkers/mapreduce_checker.py | -1 | abstractmethod | ref | function | none |
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/mapreduce_checker.py | pylint/checkers/mapreduce_checker.py | -1 | get_map_data | ref | function | none |
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/mapreduce_checker.py | pylint/checkers/mapreduce_checker.py | -1 | self | ref | function | none |
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/mapreduce_checker.py | pylint/checkers/mapreduce_checker.py | -1 | @abc | ref | function | none |
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/mapreduce_checker.py | pylint/checkers/mapreduce_checker.py | -1 | abstractmethod | ref | function | none |
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/mapreduce_checker.py | pylint/checkers/mapreduce_checker.py | -1 | reduce_map_data | ref | function | none |
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/mapreduce_checker.py | pylint/checkers/mapreduce_checker.py | -1 | self | ref | function | none |
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/mapreduce_checker.py | pylint/checkers/mapreduce_checker.py | -1 | linter | ref | function | none |
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/mapreduce_checker.py | pylint/checkers/mapreduce_checker.py | -1 | data | ref | function | none |
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/misc.py | pylint/checkers/misc.py | 44 | ByIdManagedMessagesChecker | def | class | _clear_by_id_managed_msgs _get_by_id_managed_msgs process_module |
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/misc.py | pylint/checkers/misc.py | 59 | _clear_by_id_managed_msgs | def | function | def _clear_by_id_managed_msgs(self) -> None:
self.linter._by_id_managed_msgs.clear()
def _get_by_id_managed_msgs(self) -> List[ManagedMessage]:
return self.linter._by_id_managed_msgs
def process_module(self, node: nodes.Module) -> None:
"""Inspect the source file to find messages activated or deactivated by id."""
managed_msgs = self._get_by_id_managed_msgs()
for (mod_name, msgid, symbol, lineno, is_disabled) in managed_msgs:
if mod_name == node.name:
verb = "disable" if is_disabled else "enable"
txt = f"'{msgid}' is cryptic: use '# pylint: {verb}={symbol}' instead"
self.add_message("use-symbolic-message-instead", line=lineno, args=txt)
self._clear_by_id_managed_msgs()
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/misc.py | pylint/checkers/misc.py | 62 | _get_by_id_managed_msgs | def | function | def _get_by_id_managed_msgs(self) -> List[ManagedMessage]:
return self.linter._by_id_managed_msgs
def process_module(self, node: nodes.Module) -> None:
"""Inspect the source file to find messages activated or deactivated by id."""
managed_msgs = self._get_by_id_managed_msgs()
for (mod_name, msgid, symbol, lineno, is_disabled) in managed_msgs:
if mod_name == node.name:
verb = "disable" if is_disabled else "enable"
txt = f"'{msgid}' is cryptic: use '# pylint: {verb}={symbol}' instead"
self.add_message("use-symbolic-message-instead", line=lineno, args=txt)
self._clear_by_id_managed_msgs()
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/misc.py | pylint/checkers/misc.py | 65 | process_module | def | function | def process_module(self, node: nodes.Module) -> None:
"""Inspect the source file to find messages activated or deactivated by id."""
managed_msgs = self._get_by_id_managed_msgs()
for (mod_name, msgid, symbol, lineno, is_disabled) in managed_msgs:
if mod_name == node.name:
verb = "disable" if is_disabled else "enable"
txt = f"'{msgid}' is cryptic: use '# pylint: {verb}={symbol}' instead"
self.add_message("use-symbolic-message-instead", line=lineno, args=txt)
self._clear_by_id_managed_msgs()
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/misc.py | pylint/checkers/misc.py | 67 | _get_by_id_managed_msgs | ref | function | managed_msgs = self._get_by_id_managed_msgs()
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/misc.py | pylint/checkers/misc.py | 72 | add_message | ref | function | self.add_message("use-symbolic-message-instead", line=lineno, args=txt)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/misc.py | pylint/checkers/misc.py | 73 | _clear_by_id_managed_msgs | ref | function | self._clear_by_id_managed_msgs()
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/misc.py | pylint/checkers/misc.py | 76 | EncodingChecker | def | class | open _check_encoding process_module process_tokens |
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/misc.py | pylint/checkers/misc.py | 129 | _check_encoding | def | function | def _check_encoding(
self, lineno: int, line: bytes, file_encoding: str
) -> Optional[str]:
try:
return line.decode(file_encoding)
except UnicodeDecodeError:
pass
except LookupError:
if (
line.startswith(b"#")
and "coding" in str(line)
and file_encoding in str(line)
):
msg = f"Cannot decode using encoding '{file_encoding}', bad encoding"
self.add_message("syntax-error", line=lineno, args=msg)
return None
def process_module(self, node: nodes.Module) -> None:
"""Inspect the source file to find encoding problem."""
encoding = node.file_encoding if node.file_encoding else "ascii"
with node.stream() as stream:
for lineno, line in enumerate(stream):
self._check_encoding(lineno + 1, line, encoding)
def process_tokens(self, tokens):
"""Inspect the source to find fixme problems."""
if not self.config.notes:
return
comments = (
token_info for token_info in tokens if token_info.type == tokenize.COMMENT
)
for comment in comments:
comment_text = comment.string[1:].lstrip() # trim '#' and whitespaces
# handle pylint disable clauses
disable_option_match = OPTION_PO.search(comment_text)
if disable_option_match:
try:
values = []
try:
for pragma_repr in (
p_rep
for p_rep in parse_pragma(disable_option_match.group(2))
if p_rep.action == "disable"
):
values.extend(pragma_repr.messages)
except PragmaParserError:
# Printing useful information dealing with this error is done in the lint package
pass
if set(values) & set(self.config.notes):
continue
except ValueError:
self.add_message(
"bad-inline-option",
args=disable_option_match.group(1).strip(),
line=comment.start[0],
)
continue
# emit warnings if necessary
match = self._fixme_pattern.search("#" + comment_text.lower())
if match:
self.add_message(
"fixme",
col_offset=comment.start[1] + 1,
args=comment_text,
line=comment.start[0],
)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/misc.py | pylint/checkers/misc.py | 133 | decode | ref | function | return line.decode(file_encoding)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/misc.py | pylint/checkers/misc.py | 143 | add_message | ref | function | self.add_message("syntax-error", line=lineno, args=msg)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/misc.py | pylint/checkers/misc.py | 146 | process_module | def | function | def process_module(self, node: nodes.Module) -> None:
"""Inspect the source file to find messages activated or deactivated by id."""
managed_msgs = self._get_by_id_managed_msgs()
for (mod_name, msgid, symbol, lineno, is_disabled) in managed_msgs:
if mod_name == node.name:
verb = "disable" if is_disabled else "enable"
txt = f"'{msgid}' is cryptic: use '# pylint: {verb}={symbol}' instead"
self.add_message("use-symbolic-message-instead", line=lineno, args=txt)
self._clear_by_id_managed_msgs()
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/misc.py | pylint/checkers/misc.py | 150 | stream | ref | function | with node.stream() as stream:
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/misc.py | pylint/checkers/misc.py | 152 | _check_encoding | ref | function | self._check_encoding(lineno + 1, line, encoding)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/misc.py | pylint/checkers/misc.py | 154 | process_tokens | def | function | def process_tokens(self, tokens):
"""Inspect the source to find fixme problems."""
if not self.config.notes:
return
comments = (
token_info for token_info in tokens if token_info.type == tokenize.COMMENT
)
for comment in comments:
comment_text = comment.string[1:].lstrip() # trim '#' and whitespaces
# handle pylint disable clauses
disable_option_match = OPTION_PO.search(comment_text)
if disable_option_match:
try:
values = []
try:
for pragma_repr in (
p_rep
for p_rep in parse_pragma(disable_option_match.group(2))
if p_rep.action == "disable"
):
values.extend(pragma_repr.messages)
except PragmaParserError:
# Printing useful information dealing with this error is done in the lint package
pass
if set(values) & set(self.config.notes):
continue
except ValueError:
self.add_message(
"bad-inline-option",
args=disable_option_match.group(1).strip(),
line=comment.start[0],
)
continue
# emit warnings if necessary
match = self._fixme_pattern.search("#" + comment_text.lower())
if match:
self.add_message(
"fixme",
col_offset=comment.start[1] + 1,
args=comment_text,
line=comment.start[0],
)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/misc.py | pylint/checkers/misc.py | 172 | parse_pragma | ref | function | for p_rep in parse_pragma(disable_option_match.group(2))
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/misc.py | pylint/checkers/misc.py | 182 | add_message | ref | function | self.add_message(
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/misc.py | pylint/checkers/misc.py | 192 | add_message | ref | function | self.add_message(
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/misc.py | pylint/checkers/misc.py | 200 | register | def | function | def register(linter: "PyLinter") -> None:
linter.register_checker(EncodingChecker(linter))
linter.register_checker(ByIdManagedMessagesChecker(linter))
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/misc.py | pylint/checkers/misc.py | 201 | register_checker | ref | function | linter.register_checker(EncodingChecker(linter))
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/misc.py | pylint/checkers/misc.py | 201 | EncodingChecker | ref | function | linter.register_checker(EncodingChecker(linter))
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/misc.py | pylint/checkers/misc.py | 202 | register_checker | ref | function | linter.register_checker(ByIdManagedMessagesChecker(linter))
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/misc.py | pylint/checkers/misc.py | 202 | ByIdManagedMessagesChecker | ref | function | linter.register_checker(ByIdManagedMessagesChecker(linter))
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/modified_iterating_checker.py | pylint/checkers/modified_iterating_checker.py | 18 | ModifiedIterationChecker | def | class | visit_for _modified_iterating_check_on_node_and_children _modified_iterating_check _is_node_expr_that_calls_attribute_name _common_cond_list_set _is_node_assigns_subscript_name _modified_iterating_list_cond _modified_iterating_dict_cond _modified_iterating_set_cond |
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/modified_iterating_checker.py | pylint/checkers/modified_iterating_checker.py | 53 | check_messages | ref | function | @utils.check_messages(
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/modified_iterating_checker.py | pylint/checkers/modified_iterating_checker.py | 56 | visit_for | def | function | def visit_for(self, node: nodes.For) -> None:
iter_obj = node.iter
for body_node in node.body:
self._modified_iterating_check_on_node_and_children(body_node, iter_obj)
def _modified_iterating_check_on_node_and_children(
self, body_node: nodes.NodeNG, iter_obj: nodes.NodeNG
) -> None:
"""See if node or any of its children raises modified iterating messages."""
self._modified_iterating_check(body_node, iter_obj)
for child in body_node.get_children():
self._modified_iterating_check_on_node_and_children(child, iter_obj)
def _modified_iterating_check(
self, node: nodes.NodeNG, iter_obj: nodes.NodeNG
) -> None:
msg_id = None
if self._modified_iterating_list_cond(node, iter_obj):
msg_id = "modified-iterating-list"
elif self._modified_iterating_dict_cond(node, iter_obj):
msg_id = "modified-iterating-dict"
elif self._modified_iterating_set_cond(node, iter_obj):
msg_id = "modified-iterating-set"
if msg_id:
self.add_message(
msg_id,
node=node,
args=(iter_obj.name,),
confidence=interfaces.INFERENCE,
)
@staticmethod
def _is_node_expr_that_calls_attribute_name(node: nodes.NodeNG) -> bool:
return (
isinstance(node, nodes.Expr)
and isinstance(node.value, nodes.Call)
and isinstance(node.value.func, nodes.Attribute)
and isinstance(node.value.func.expr, nodes.Name)
)
@staticmethod
def _common_cond_list_set(
node: nodes.Expr,
iter_obj: nodes.NodeNG,
infer_val: Union[nodes.List, nodes.Set],
) -> bool:
return (infer_val == utils.safe_infer(iter_obj)) and (
node.value.func.expr.name == iter_obj.name
)
@staticmethod
def _is_node_assigns_subscript_name(node: nodes.NodeNG) -> bool:
return isinstance(node, nodes.Assign) and (
isinstance(node.targets[0], nodes.Subscript)
and (isinstance(node.targets[0].value, nodes.Name))
)
def _modified_iterating_list_cond(
self, node: nodes.NodeNG, iter_obj: nodes.NodeNG
) -> bool:
if not self._is_node_expr_that_calls_attribute_name(node):
return _False
infer_val = utils.safe_infer(node.value.func.expr)
if not isinstance(infer_val, nodes.List):
return _False
return (
self._common_cond_list_set(node, iter_obj, infer_val)
and node.value.func.attrname in _LIST_MODIFIER_METHODS
)
def _modified_iterating_dict_cond(
self, node: nodes.NodeNG, iter_obj: nodes.NodeNG
) -> bool:
if not self._is_node_assigns_subscript_name(node):
return _False
infer_val = utils.safe_infer(node.targets[0].value)
if not isinstance(infer_val, nodes.Dict):
return _False
if infer_val != utils.safe_infer(iter_obj):
return _False
return node.targets[0].value.name == iter_obj.name
def _modified_iterating_set_cond(
self, node: nodes.NodeNG, iter_obj: nodes.NodeNG
) -> bool:
if not self._is_node_expr_that_calls_attribute_name(node):
return _False
infer_val = utils.safe_infer(node.value.func.expr)
if not isinstance(infer_val, nodes.Set):
return _False
return (
self._common_cond_list_set(node, iter_obj, infer_val)
and node.value.func.attrname in _SET_MODIFIER_METHODS
)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/modified_iterating_checker.py | pylint/checkers/modified_iterating_checker.py | 59 | _modified_iterating_check_on_node_and_children | ref | function | self._modified_iterating_check_on_node_and_children(body_node, iter_obj)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/modified_iterating_checker.py | pylint/checkers/modified_iterating_checker.py | 61 | _modified_iterating_check_on_node_and_children | def | function | def _modified_iterating_check_on_node_and_children(
self, body_node: nodes.NodeNG, iter_obj: nodes.NodeNG
) -> None:
"""See if node or any of its children raises modified iterating messages."""
self._modified_iterating_check(body_node, iter_obj)
for child in body_node.get_children():
self._modified_iterating_check_on_node_and_children(child, iter_obj)
def _modified_iterating_check(
self, node: nodes.NodeNG, iter_obj: nodes.NodeNG
) -> None:
msg_id = None
if self._modified_iterating_list_cond(node, iter_obj):
msg_id = "modified-iterating-list"
elif self._modified_iterating_dict_cond(node, iter_obj):
msg_id = "modified-iterating-dict"
elif self._modified_iterating_set_cond(node, iter_obj):
msg_id = "modified-iterating-set"
if msg_id:
self.add_message(
msg_id,
node=node,
args=(iter_obj.name,),
confidence=interfaces.INFERENCE,
)
@staticmethod
def _is_node_expr_that_calls_attribute_name(node: nodes.NodeNG) -> bool:
return (
isinstance(node, nodes.Expr)
and isinstance(node.value, nodes.Call)
and isinstance(node.value.func, nodes.Attribute)
and isinstance(node.value.func.expr, nodes.Name)
)
@staticmethod
def _common_cond_list_set(
node: nodes.Expr,
iter_obj: nodes.NodeNG,
infer_val: Union[nodes.List, nodes.Set],
) -> bool:
return (infer_val == utils.safe_infer(iter_obj)) and (
node.value.func.expr.name == iter_obj.name
)
@staticmethod
def _is_node_assigns_subscript_name(node: nodes.NodeNG) -> bool:
return isinstance(node, nodes.Assign) and (
isinstance(node.targets[0], nodes.Subscript)
and (isinstance(node.targets[0].value, nodes.Name))
)
def _modified_iterating_list_cond(
self, node: nodes.NodeNG, iter_obj: nodes.NodeNG
) -> bool:
if not self._is_node_expr_that_calls_attribute_name(node):
return _False
infer_val = utils.safe_infer(node.value.func.expr)
if not isinstance(infer_val, nodes.List):
return _False
return (
self._common_cond_list_set(node, iter_obj, infer_val)
and node.value.func.attrname in _LIST_MODIFIER_METHODS
)
def _modified_iterating_dict_cond(
self, node: nodes.NodeNG, iter_obj: nodes.NodeNG
) -> bool:
if not self._is_node_assigns_subscript_name(node):
return _False
infer_val = utils.safe_infer(node.targets[0].value)
if not isinstance(infer_val, nodes.Dict):
return _False
if infer_val != utils.safe_infer(iter_obj):
return _False
return node.targets[0].value.name == iter_obj.name
def _modified_iterating_set_cond(
self, node: nodes.NodeNG, iter_obj: nodes.NodeNG
) -> bool:
if not self._is_node_expr_that_calls_attribute_name(node):
return _False
infer_val = utils.safe_infer(node.value.func.expr)
if not isinstance(infer_val, nodes.Set):
return _False
return (
self._common_cond_list_set(node, iter_obj, infer_val)
and node.value.func.attrname in _SET_MODIFIER_METHODS
)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/modified_iterating_checker.py | pylint/checkers/modified_iterating_checker.py | 65 | _modified_iterating_check | ref | function | self._modified_iterating_check(body_node, iter_obj)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/modified_iterating_checker.py | pylint/checkers/modified_iterating_checker.py | 66 | get_children | ref | function | for child in body_node.get_children():
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/modified_iterating_checker.py | pylint/checkers/modified_iterating_checker.py | 67 | _modified_iterating_check_on_node_and_children | ref | function | self._modified_iterating_check_on_node_and_children(child, iter_obj)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/modified_iterating_checker.py | pylint/checkers/modified_iterating_checker.py | 69 | _modified_iterating_check | def | function | def _modified_iterating_check(
self, node: nodes.NodeNG, iter_obj: nodes.NodeNG
) -> None:
msg_id = None
if self._modified_iterating_list_cond(node, iter_obj):
msg_id = "modified-iterating-list"
elif self._modified_iterating_dict_cond(node, iter_obj):
msg_id = "modified-iterating-dict"
elif self._modified_iterating_set_cond(node, iter_obj):
msg_id = "modified-iterating-set"
if msg_id:
self.add_message(
msg_id,
node=node,
args=(iter_obj.name,),
confidence=interfaces.INFERENCE,
)
@staticmethod
def _is_node_expr_that_calls_attribute_name(node: nodes.NodeNG) -> bool:
return (
isinstance(node, nodes.Expr)
and isinstance(node.value, nodes.Call)
and isinstance(node.value.func, nodes.Attribute)
and isinstance(node.value.func.expr, nodes.Name)
)
@staticmethod
def _common_cond_list_set(
node: nodes.Expr,
iter_obj: nodes.NodeNG,
infer_val: Union[nodes.List, nodes.Set],
) -> bool:
return (infer_val == utils.safe_infer(iter_obj)) and (
node.value.func.expr.name == iter_obj.name
)
@staticmethod
def _is_node_assigns_subscript_name(node: nodes.NodeNG) -> bool:
return isinstance(node, nodes.Assign) and (
isinstance(node.targets[0], nodes.Subscript)
and (isinstance(node.targets[0].value, nodes.Name))
)
def _modified_iterating_list_cond(
self, node: nodes.NodeNG, iter_obj: nodes.NodeNG
) -> bool:
if not self._is_node_expr_that_calls_attribute_name(node):
return _False
infer_val = utils.safe_infer(node.value.func.expr)
if not isinstance(infer_val, nodes.List):
return _False
return (
self._common_cond_list_set(node, iter_obj, infer_val)
and node.value.func.attrname in _LIST_MODIFIER_METHODS
)
def _modified_iterating_dict_cond(
self, node: nodes.NodeNG, iter_obj: nodes.NodeNG
) -> bool:
if not self._is_node_assigns_subscript_name(node):
return _False
infer_val = utils.safe_infer(node.targets[0].value)
if not isinstance(infer_val, nodes.Dict):
return _False
if infer_val != utils.safe_infer(iter_obj):
return _False
return node.targets[0].value.name == iter_obj.name
def _modified_iterating_set_cond(
self, node: nodes.NodeNG, iter_obj: nodes.NodeNG
) -> bool:
if not self._is_node_expr_that_calls_attribute_name(node):
return _False
infer_val = utils.safe_infer(node.value.func.expr)
if not isinstance(infer_val, nodes.Set):
return _False
return (
self._common_cond_list_set(node, iter_obj, infer_val)
and node.value.func.attrname in _SET_MODIFIER_METHODS
)
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/modified_iterating_checker.py | pylint/checkers/modified_iterating_checker.py | 73 | _modified_iterating_list_cond | ref | function | if self._modified_iterating_list_cond(node, iter_obj):
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/modified_iterating_checker.py | pylint/checkers/modified_iterating_checker.py | 75 | _modified_iterating_dict_cond | ref | function | elif self._modified_iterating_dict_cond(node, iter_obj):
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/modified_iterating_checker.py | pylint/checkers/modified_iterating_checker.py | 77 | _modified_iterating_set_cond | ref | function | elif self._modified_iterating_set_cond(node, iter_obj):
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/modified_iterating_checker.py | pylint/checkers/modified_iterating_checker.py | 80 | add_message | ref | function | self.add_message(
|
playground/e9b22a58-260b-483f-88d7-7a5fe9f8b1d4/pylint/pylint/checkers/modified_iterating_checker.py | pylint/checkers/modified_iterating_checker.py | 88 | _is_node_expr_that_calls_attribute_name | def | function | def _is_node_expr_that_calls_attribute_name(node: nodes.NodeNG) -> bool:
return (
isinstance(node, nodes.Expr)
and isinstance(node.value, nodes.Call)
and isinstance(node.value.func, nodes.Attribute)
and isinstance(node.value.func.expr, nodes.Name)
)
@staticmethod
def _common_cond_list_set(
node: nodes.Expr,
iter_obj: nodes.NodeNG,
infer_val: Union[nodes.List, nodes.Set],
) -> bool:
return (infer_val == utils.safe_infer(iter_obj)) and (
node.value.func.expr.name == iter_obj.name
)
@staticmethod
def _is_node_assigns_subscript_name(node: nodes.NodeNG) -> bool:
return isinstance(node, nodes.Assign) and (
isinstance(node.targets[0], nodes.Subscript)
and (isinstance(node.targets[0].value, nodes.Name))
)
def _modified_iterating_list_cond(
self, node: nodes.NodeNG, iter_obj: nodes.NodeNG
) -> bool:
if not self._is_node_expr_that_calls_attribute_name(node):
return _False
infer_val = utils.safe_infer(node.value.func.expr)
if not isinstance(infer_val, nodes.List):
return _False
return (
self._common_cond_list_set(node, iter_obj, infer_val)
and node.value.func.attrname in _LIST_MODIFIER_METHODS
)
def _modified_iterating_dict_cond(
self, node: nodes.NodeNG, iter_obj: nodes.NodeNG
) -> bool:
if not self._is_node_assigns_subscript_name(node):
return _False
infer_val = utils.safe_infer(node.targets[0].value)
if not isinstance(infer_val, nodes.Dict):
return _False
if infer_val != utils.safe_infer(iter_obj):
return _False
return node.targets[0].value.name == iter_obj.name
def _modified_iterating_set_cond(
self, node: nodes.NodeNG, iter_obj: nodes.NodeNG
) -> bool:
if not self._is_node_expr_that_calls_attribute_name(node):
return _False
infer_val = utils.safe_infer(node.value.func.expr)
if not isinstance(infer_val, nodes.Set):
return _False
return (
self._common_cond_list_set(node, iter_obj, infer_val)
and node.value.func.attrname in _SET_MODIFIER_METHODS
)
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.