mirror of https://github.com/scrapy/scrapy.git
flake8-bugbear
This commit is contained in:
parent
1ef9c337ca
commit
3d8dbd5648
15
.flake8
15
.flake8
|
|
@ -4,6 +4,21 @@ max-line-length = 119
|
||||||
ignore =
|
ignore =
|
||||||
# black disagrees with flake8 about these
|
# black disagrees with flake8 about these
|
||||||
E203, E501, E701, E704, W503
|
E203, E501, E701, E704, W503
|
||||||
|
# Assigning to `os.environ` doesn't clear the environment.
|
||||||
|
B003
|
||||||
|
# Do not use mutable data structures for argument defaults.
|
||||||
|
B006
|
||||||
|
# Loop control variable not used within the loop body.
|
||||||
|
B007
|
||||||
|
# Do not perform function calls in argument defaults.
|
||||||
|
B008
|
||||||
|
# return/continue/break inside finally blocks cause exceptions to be
|
||||||
|
# silenced.
|
||||||
|
B012
|
||||||
|
# Star-arg unpacking after a keyword argument is strongly discouraged
|
||||||
|
B026
|
||||||
|
# No explicit stacklevel argument found.
|
||||||
|
B028
|
||||||
# docstring does contain unindexed parameters
|
# docstring does contain unindexed parameters
|
||||||
P102
|
P102
|
||||||
# other string does contain unindexed parameters
|
# other string does contain unindexed parameters
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ repos:
|
||||||
hooks:
|
hooks:
|
||||||
- id: flake8
|
- id: flake8
|
||||||
additional_dependencies:
|
additional_dependencies:
|
||||||
|
- flake8-bugbear
|
||||||
- flake8-comprehensions
|
- flake8-comprehensions
|
||||||
- flake8-debugger
|
- flake8-debugger
|
||||||
- flake8-docstrings
|
- flake8-docstrings
|
||||||
|
|
|
||||||
|
|
@ -234,7 +234,7 @@ class MediaPipeline(ABC):
|
||||||
# Exception Chaining (https://www.python.org/dev/peps/pep-3134/).
|
# Exception Chaining (https://www.python.org/dev/peps/pep-3134/).
|
||||||
context = getattr(result.value, "__context__", None)
|
context = getattr(result.value, "__context__", None)
|
||||||
if isinstance(context, StopIteration):
|
if isinstance(context, StopIteration):
|
||||||
setattr(result.value, "__context__", None)
|
result.value.__context__ = None
|
||||||
|
|
||||||
info.downloading.remove(fp)
|
info.downloading.remove(fp)
|
||||||
info.downloaded[fp] = result # cache result
|
info.downloaded[fp] = result # cache result
|
||||||
|
|
|
||||||
|
|
@ -407,7 +407,7 @@ def maybeDeferred_coro(
|
||||||
"""Copy of defer.maybeDeferred that also converts coroutines to Deferreds."""
|
"""Copy of defer.maybeDeferred that also converts coroutines to Deferreds."""
|
||||||
try:
|
try:
|
||||||
result = f(*args, **kw)
|
result = f(*args, **kw)
|
||||||
except: # noqa: E722
|
except: # noqa: E722,B001
|
||||||
return defer.fail(failure.Failure(captureVars=Deferred.debug))
|
return defer.fail(failure.Failure(captureVars=Deferred.debug))
|
||||||
|
|
||||||
if isinstance(result, Deferred):
|
if isinstance(result, Deferred):
|
||||||
|
|
|
||||||
|
|
@ -269,7 +269,7 @@ def get_spec(func: Callable[..., Any]) -> Tuple[List[str], Dict[str, Any]]:
|
||||||
|
|
||||||
if inspect.isfunction(func) or inspect.ismethod(func):
|
if inspect.isfunction(func) or inspect.ismethod(func):
|
||||||
spec = inspect.getfullargspec(func)
|
spec = inspect.getfullargspec(func)
|
||||||
elif hasattr(func, "__call__"):
|
elif hasattr(func, "__call__"): # noqa: B004
|
||||||
spec = inspect.getfullargspec(func.__call__)
|
spec = inspect.getfullargspec(func.__call__)
|
||||||
else:
|
else:
|
||||||
raise TypeError(f"{type(func)} is not callable")
|
raise TypeError(f"{type(func)} is not callable")
|
||||||
|
|
|
||||||
|
|
@ -100,7 +100,10 @@ def send_catch_log_deferred(
|
||||||
d.addErrback(logerror, receiver)
|
d.addErrback(logerror, receiver)
|
||||||
# TODO https://pylint.readthedocs.io/en/latest/user_guide/messages/warning/cell-var-from-loop.html
|
# TODO https://pylint.readthedocs.io/en/latest/user_guide/messages/warning/cell-var-from-loop.html
|
||||||
d.addBoth(
|
d.addBoth(
|
||||||
lambda result: (receiver, result) # pylint: disable=cell-var-from-loop
|
lambda result: (
|
||||||
|
receiver, # pylint: disable=cell-var-from-loop # noqa: B023
|
||||||
|
result,
|
||||||
|
)
|
||||||
)
|
)
|
||||||
dfds.append(d)
|
dfds.append(d)
|
||||||
d = DeferredList(dfds)
|
d = DeferredList(dfds)
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ class CmdlineTest(unittest.TestCase):
|
||||||
self.env["SCRAPY_SETTINGS_MODULE"] = "tests.test_cmdline.settings"
|
self.env["SCRAPY_SETTINGS_MODULE"] = "tests.test_cmdline.settings"
|
||||||
|
|
||||||
def _execute(self, *new_args, **kwargs):
|
def _execute(self, *new_args, **kwargs):
|
||||||
encoding = getattr(sys.stdout, "encoding") or "utf-8"
|
encoding = sys.stdout.encoding or "utf-8"
|
||||||
args = (sys.executable, "-m", "scrapy.cmdline") + new_args
|
args = (sys.executable, "-m", "scrapy.cmdline") + new_args
|
||||||
proc = Popen(args, stdout=PIPE, stderr=PIPE, env=self.env, **kwargs)
|
proc = Popen(args, stdout=PIPE, stderr=PIPE, env=self.env, **kwargs)
|
||||||
comm = proc.communicate()[0].strip()
|
comm = proc.communicate()[0].strip()
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ class VersionTest(ProcessTest, unittest.TestCase):
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def test_output(self):
|
def test_output(self):
|
||||||
encoding = getattr(sys.stdout, "encoding") or "utf-8"
|
encoding = sys.stdout.encoding or "utf-8"
|
||||||
_, out, _ = yield self.execute([])
|
_, out, _ = yield self.execute([])
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
out.strip().decode(encoding),
|
out.strip().decode(encoding),
|
||||||
|
|
@ -21,7 +21,7 @@ class VersionTest(ProcessTest, unittest.TestCase):
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def test_verbose_output(self):
|
def test_verbose_output(self):
|
||||||
encoding = getattr(sys.stdout, "encoding") or "utf-8"
|
encoding = sys.stdout.encoding or "utf-8"
|
||||||
_, out, _ = yield self.execute(["-v"])
|
_, out, _ = yield self.execute(["-v"])
|
||||||
headers = [
|
headers = [
|
||||||
line.partition(":")[0].strip()
|
line.partition(":")[0].strip()
|
||||||
|
|
|
||||||
|
|
@ -101,7 +101,7 @@ class ProjectTest(unittest.TestCase):
|
||||||
def kill_proc():
|
def kill_proc():
|
||||||
p.kill()
|
p.kill()
|
||||||
p.communicate()
|
p.communicate()
|
||||||
assert False, "Command took too much time to complete"
|
raise AssertionError("Command took too much time to complete")
|
||||||
|
|
||||||
timer = Timer(15, kill_proc)
|
timer = Timer(15, kill_proc)
|
||||||
try:
|
try:
|
||||||
|
|
|
||||||
|
|
@ -892,7 +892,7 @@ class S3TestCase(unittest.TestCase):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.assertIsInstance(e, (TypeError, NotConfigured))
|
self.assertIsInstance(e, (TypeError, NotConfigured))
|
||||||
else:
|
else:
|
||||||
assert False
|
raise AssertionError()
|
||||||
|
|
||||||
def test_request_signing1(self):
|
def test_request_signing1(self):
|
||||||
# gets an object from the johnsmith bucket.
|
# gets an object from the johnsmith bucket.
|
||||||
|
|
|
||||||
|
|
@ -459,7 +459,7 @@ class EngineTest(unittest.TestCase):
|
||||||
def kill_proc():
|
def kill_proc():
|
||||||
p.kill()
|
p.kill()
|
||||||
p.communicate()
|
p.communicate()
|
||||||
assert False, "Command took too much time to complete"
|
raise AssertionError("Command took too much time to complete")
|
||||||
|
|
||||||
timer = Timer(15, kill_proc)
|
timer = Timer(15, kill_proc)
|
||||||
try:
|
try:
|
||||||
|
|
|
||||||
|
|
@ -147,7 +147,7 @@ class RequestSerializationTest(unittest.TestCase):
|
||||||
|
|
||||||
spider = MySpider()
|
spider = MySpider()
|
||||||
r = Request("http://www.example.com", callback=spider.parse)
|
r = Request("http://www.example.com", callback=spider.parse)
|
||||||
setattr(spider, "parse", None)
|
spider.parse = None
|
||||||
self.assertRaises(ValueError, r.to_dict, spider=spider)
|
self.assertRaises(ValueError, r.to_dict, spider=spider)
|
||||||
|
|
||||||
def test_callback_not_available(self):
|
def test_callback_not_available(self):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue