mirror of
https://github.com/scrapy/scrapy.git
synced 2025-02-23 10:43:44 +00:00
Restore compatibility with Settings.overrides while still deprecating it
This commit is contained in:
parent
1b32ece918
commit
f224ac1328
@ -1,8 +1,10 @@
|
||||
import six
|
||||
import json
|
||||
import warnings
|
||||
from importlib import import_module
|
||||
|
||||
from scrapy.utils.deprecate import create_deprecated_class
|
||||
from scrapy.exceptions import ScrapyDeprecationWarning
|
||||
|
||||
from . import default_settings
|
||||
|
||||
@ -108,6 +110,22 @@ class Settings(object):
|
||||
if key.isupper():
|
||||
self.set(key, getattr(module, key), priority)
|
||||
|
||||
@property
|
||||
def overrides(self):
|
||||
warnings.warn("`Settings.overrides` attribute is deprecated and won't "
|
||||
"be supported in Scrapy 0.26, use "
|
||||
"`Settings.set(name, value, priority='cmdline')` instead",
|
||||
category=ScrapyDeprecationWarning, stacklevel=2)
|
||||
try:
|
||||
o = self._overrides
|
||||
except AttributeError:
|
||||
class _DictProxy(dict):
|
||||
def __setitem__(this, key, value):
|
||||
super(_DictProxy, this).__setitem__(key, value)
|
||||
self.set(key, value, priority='cmdline')
|
||||
self._overrides = o = _DictProxy()
|
||||
return o
|
||||
|
||||
|
||||
class CrawlerSettings(Settings):
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
import six
|
||||
import unittest
|
||||
import warnings
|
||||
try:
|
||||
from unittest import mock
|
||||
except ImportError:
|
||||
@ -189,7 +190,15 @@ class SettingsTest(unittest.TestCase):
|
||||
self.assertEqual(settings.getdict('TEST_DICT3', {'key1': 5}), {'key1': 5})
|
||||
self.assertRaises(ValueError, settings.getdict, 'TEST_LIST1')
|
||||
|
||||
def test_deprecated_attribute(self):
|
||||
self.settings.set('BAR', 'fuz', priority='cmdline')
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
self.settings.overrides['BAR'] = 'foo'
|
||||
self.assertIn("Settings.overrides", str(w[0].message))
|
||||
self.assertEqual(self.settings.get('BAR'), 'foo')
|
||||
self.assertEqual(self.settings.overrides.get('BAR'), 'foo')
|
||||
self.assertIn('BAR', self.settings.overrides)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user