Refactor warnings in spiderloader

This commit is contained in:
Eugenio Lacuesta 2020-05-07 12:48:43 -03:00
parent 8659b0d896
commit e0127a3123
No known key found for this signature in database
GPG Key ID: DA3EF2D0913E9810
1 changed files with 12 additions and 7 deletions

View File

@ -35,9 +35,11 @@ class SpiderLoader:
if dupes:
dupes_string = "\n\n".join(dupes)
msg = ("There are several spiders with the same name:\n\n"
"{}\n\n This can cause unexpected behavior.".format(dupes_string))
warnings.warn(msg, UserWarning)
warnings.warn(
"There are several spiders with the same name:\n\n"
"{}\n\n This can cause unexpected behavior.".format(dupes_string),
category=UserWarning,
)
def _load_spiders(self, module):
for spcls in iter_spider_classes(module):
@ -51,10 +53,13 @@ class SpiderLoader:
self._load_spiders(module)
except ImportError:
if self.warn_only:
msg = ("\n{tb}Could not load spiders from module '{modname}'. "
"See above traceback for details.".format(
modname=name, tb=traceback.format_exc()))
warnings.warn(msg, RuntimeWarning)
warnings.warn(
"\n{tb}Could not load spiders from module '{modname}'. "
"See above traceback for details.".format(
modname=name, tb=traceback.format_exc()
),
category=RuntimeWarning,
)
else:
raise
self._check_name_duplicates()