Skip to content

Commit

Permalink
Remove redundant W503 inline ignores (#233)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpy-git committed Mar 20, 2022
1 parent c5223e0 commit 83a8227
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
38 changes: 19 additions & 19 deletions bugbear.py
Expand Up @@ -303,21 +303,21 @@ def visit_Call(self, node):
with suppress(AttributeError, IndexError):
if (
node.func.id in ("getattr", "hasattr")
and node.args[1].s == "__call__" # noqa: W503
and node.args[1].s == "__call__"
):
self.errors.append(B004(node.lineno, node.col_offset))
if (
node.func.id == "getattr"
and len(node.args) == 2 # noqa: W503
and _is_identifier(node.args[1]) # noqa: W503
and not iskeyword(node.args[1].s) # noqa: W503
and len(node.args) == 2
and _is_identifier(node.args[1])
and not iskeyword(node.args[1].s)
):
self.errors.append(B009(node.lineno, node.col_offset))
elif (
node.func.id == "setattr"
and len(node.args) == 3 # noqa: W503
and _is_identifier(node.args[1]) # noqa: W503
and not iskeyword(node.args[1].s) # noqa: W503
and len(node.args) == 3
and _is_identifier(node.args[1])
and not iskeyword(node.args[1].s)
):
self.errors.append(B010(node.lineno, node.col_offset))

Expand Down Expand Up @@ -500,12 +500,12 @@ def check_for_b017(self, node):
item_context = item.context_expr
if (
hasattr(item_context, "func")
and hasattr(item_context.func, "attr") # noqa W503
and item_context.func.attr == "assertRaises" # noqa W503
and len(item_context.args) == 1 # noqa W503
and isinstance(item_context.args[0], ast.Name) # noqa W503
and item_context.args[0].id == "Exception" # noqa W503
and not item.optional_vars # noqa W503
and hasattr(item_context.func, "attr")
and item_context.func.attr == "assertRaises"
and len(item_context.args) == 1
and isinstance(item_context.args[0], ast.Name)
and item_context.args[0].id == "Exception"
and not item.optional_vars
):
self.errors.append(B017(node.lineno, node.col_offset))

Expand Down Expand Up @@ -589,7 +589,7 @@ def check_for_b902(self, node):
if "type" in bases:
if (
"classmethod" in decorators.names
or node.name in B902.implicit_classmethods # noqa: W503
or node.name in B902.implicit_classmethods
):
expected_first_args = B902.metacls
kind = "metaclass class"
Expand All @@ -599,7 +599,7 @@ def check_for_b902(self, node):
else:
if (
"classmethod" in decorators.names
or node.name in B902.implicit_classmethods # noqa: W503
or node.name in B902.implicit_classmethods
):
expected_first_args = B902.cls
kind = "class"
Expand Down Expand Up @@ -644,16 +644,16 @@ def check_for_b903(self, node):
body = node.body
if (
body
and isinstance(body[0], ast.Expr) # noqa: W503
and isinstance(body[0].value, ast.Str) # noqa: W503
and isinstance(body[0], ast.Expr)
and isinstance(body[0].value, ast.Str)
):
# Ignore the docstring
body = body[1:]

if (
len(body) != 1
or not isinstance(body[0], ast.FunctionDef) # noqa: W503
or body[0].name != "__init__" # noqa: W503
or not isinstance(body[0], ast.FunctionDef)
or body[0].name != "__init__"
):
# only classes with *just* an __init__ method are interesting
return
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
@@ -1,7 +1,7 @@
[flake8]
# Keep in sync with .flake8. This copy here is needed for source packages
# to be able to pass tests without failing selfclean check.
ignore = E203, E302, E501, E999
ignore = E203, E302, E501, E999, W503
max-line-length = 88
max-complexity = 12
select = B,C,E,F,W,B9
Expand Down

0 comments on commit 83a8227

Please sign in to comment.