From 9f7fcf5582ed61787180df20a62a301cc09fce4a Mon Sep 17 00:00:00 2001 From: Jakob de Maeyer Date: Fri, 6 Nov 2015 22:18:10 +0100 Subject: [PATCH] Make update_classpath() util function return non-string objects --- scrapy/utils/deprecate.py | 3 +++ tests/test_utils_deprecate.py | 4 ++++ 2 files changed, 7 insertions(+) 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)