Skip to content

Scrapy, a fast high-level web crawling & scraping framework for Python.

Make update_classpath() util function return non-string objects

Jakob de Maeyer9f7fcf5582ed
diff --git a/scrapy/utils/deprecate.py b/scrapy/utils/deprecate.py
index 0fc33e0c4..9293b1480 100644
--- a/scrapy/utils/deprecate.py
+++ b/scrapy/utils/deprecate.py
@@ -1,5 +1,6 @@
"""Some helpers for deprecation messages"""
+import six
import warnings
import inspect
from scrapy.exceptions import ScrapyDeprecationWarning
@@ -149,6 +150,8 @@ DEPRECATION_RULES = [
def update_classpath(path):
"""Update a deprecated path from an object with its new location"""
+ if not isinstance(path, six.string_types):
+ return path
for prefix, replacement in DEPRECATION_RULES:
if path.startswith(prefix):
new_path = path.replace(prefix, replacement, 1)
diff --git a/tests/test_utils_deprecate.py b/tests/test_utils_deprecate.py
index 3e7236fb1..7a35c424b 100644
--- a/tests/test_utils_deprecate.py
+++ b/tests/test_utils_deprecate.py
@@ -279,3 +279,7 @@ class UpdateClassPathTest(unittest.TestCase):
output = update_classpath('scrapy.unmatched.Path')
self.assertEqual(output, 'scrapy.unmatched.Path')
self.assertEqual(len(w), 0)
+
+ def test_returns_nonstring(self):
+ for notastring in [None, True, [1, 2, 3], object()]:
+ self.assertEqual(update_classpath(notastring), notastring)