Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@check_messages("found-percent-in-_")
def visit_binop(self, node):
if node.op != "%":
return
curr = node
while curr.parent:
if isinstance(curr.parent, astroid.CallFunc) and getattr(curr.parent.func, "name", "") in translationMethods:
self.add_message("W9901", node=node)
break
curr = curr.parent
@check_messages('unreachable', 'lost-exception')
def visit_return(self, node):
"""1 - check is the node has a right sibling (if so, that's some
unreachable code)
2 - check is the node is inside the finally clause of a try...finally
block
"""
self._check_unreachable(node)
# Is it inside final body of a try...finally bloc ?
self._check_not_in_finally(node, 'return', (astroid.Function,))
@check_messages('missing-docstring', 'empty-docstring')
def visit_module(self, node):
self._check_docstring('module', node)
@utils.check_messages("unneeded-not")
def visit_unaryop(self, node):
if node.op != "not":
return
operand = node.operand
if isinstance(operand, astroid.UnaryOp) and operand.op == "not":
self.add_message(
"unneeded-not",
node=node,
args=(node.as_string(), operand.operand.as_string()),
)
elif isinstance(operand, astroid.Compare):
left = operand.left
# ignore multiple comparisons
if len(operand.ops) > 1:
return
@utils.check_messages(
"singleton-comparison",
"misplaced-comparison-constant",
"unidiomatic-typecheck",
"literal-comparison",
"comparison-with-itself",
"comparison-with-callable",
)
def visit_compare(self, node):
self._check_callable_comparison(node)
self._check_logical_tautology(node)
self._check_unidiomatic_typecheck(node)
# NOTE: this checker only works with binary comparisons like 'x == 42'
# but not 'x == y == 42'
if len(node.ops) != 1:
return
@check_messages('function-redefined')
def visit_class(self, node):
self._check_redefinition('class', node)
@utils.check_messages("exception-message-attribute", "xreadlines-attribute")
def visit_attribute(self, node):
"""Look for removed attributes"""
if node.attrname == "xreadlines":
self.add_message("xreadlines-attribute", node=node)
return
exception_message = "message"
try:
for inferred in _infer_if_relevant_attr(
node, self._deprecated_attrs | {exception_message}
):
if isinstance(inferred, astroid.Instance) and utils.inherit_from_std_ex(
inferred
):
if node.attrname == exception_message:
@utils.check_messages('boolean-datetime')
def visit_ifexp(self, node):
self._check_datetime(node.test)
@check_messages('ipa-forbidden-import')
def visit_import(self, node):
names = [n[0] for n in node.names]
self._check_forbidden_imports(node, names)
@check_messages('useless-else-on-loop')
def visit_for(self, node):
self._check_else_on_loop(node)