From 30643c142714ea48a0d9429808e31c64e4fbd2a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A1n=20Chaves?= Date: Thu, 7 May 2020 11:22:42 +0200 Subject: [PATCH] =?UTF-8?q?warn=20=E2=86=92=20warnings.warn?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scrapy/spiderloader.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/scrapy/spiderloader.py b/scrapy/spiderloader.py index 8a0b6ed82..b3dd79417 100644 --- a/scrapy/spiderloader.py +++ b/scrapy/spiderloader.py @@ -1,6 +1,6 @@ import traceback +import warnings from collections import defaultdict -from warnings import warn from zope.interface import implementer @@ -19,12 +19,14 @@ class SpiderLoader: def __init__(self, settings): self.require_name = settings.getbool('SPIDER_LOADER_REQUIRE_NAME') if self.require_name: - warn('SPIDER_LOADER_REQUIRE_NAME is True. In a future version of ' - 'Scrapy, the SPIDER_LOADER_REQUIRE_NAME setting will be ' - 'removed, and Scrapy will always behave as if ' - 'SPIDER_LOADER_REQUIRE_NAME were False. To remove this ' - 'warning, set SPIDER_LOADER_REQUIRE_NAME to False.', - ScrapyDeprecationWarning) + message = ( + 'SPIDER_LOADER_REQUIRE_NAME is True. In a future version of ' + 'Scrapy, the SPIDER_LOADER_REQUIRE_NAME setting will be ' + 'removed, and Scrapy will always behave as if ' + 'SPIDER_LOADER_REQUIRE_NAME were False. To remove this ' + 'warning, set SPIDER_LOADER_REQUIRE_NAME to False.' + ) + warnings.warn(message, ScrapyDeprecationWarning) self.spider_modules = settings.getlist('SPIDER_MODULES') self.warn_only = settings.getbool('SPIDER_LOADER_WARN_ONLY') self._spiders = {} @@ -41,7 +43,7 @@ class SpiderLoader: msg = ("There are several spiders with the same name:\n\n" "{}\n\n This can cause unexpected behavior.".format( "\n\n".join(dupes))) - warn(msg, UserWarning) + warnings.warn(msg, UserWarning) def _load_spiders(self, module): classes = iter_spider_classes(module, require_name=self.require_name) @@ -61,7 +63,7 @@ class SpiderLoader: msg = ("\n{tb}Could not load spiders from module '{modname}'. " "See above traceback for details.".format( modname=name, tb=traceback.format_exc())) - warn(msg, RuntimeWarning) + warnings.warn(msg, RuntimeWarning) else: raise self._check_name_duplicates()