scrapy: return in finally can swallow exception

Description

There are two places in scrapy/contracts/__init__.py where a finally: body contains a return statement, which would swallow any in-flight exception.

This means that if a BaseException (such as KeyboardInterrupt) is raised from the body, or any exception is raised from one of the except: clause, it will not propagate on as expected.

The pylint warning about this was suppressed in this commit but it doesn’t seem like there was justification for that.

These are the two locations: https://github.com/scrapy/scrapy/blame/b4bad97eae6bcce790a626d244c63589f4134408/scrapy/contracts/__init__.py#L56

https://github.com/scrapy/scrapy/blame/b4bad97eae6bcce790a626d244c63589f4134408/scrapy/contracts/__init__.py#L86

See also https://docs.python.org/3/tutorial/errors.html#defining-clean-up-actions.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 15 (12 by maintainers)

Commits related to this issue

Most upvoted comments

Here, specifically.

That’s unfortunate, especially as the way forward was already suggested earlier.