Add pretty-printting of settings as dict if using IPython shell

Suggested by @digenis
see http://ipython.readthedocs.org/en/stable/api/generated/IPython.lib.pretty.html?#extending
This commit is contained in:
Paul Tremberth 2016-02-01 12:43:27 +01:00
parent d843a0aae8
commit 268e912273
1 changed files with 7 additions and 0 deletions

View File

@ -4,6 +4,7 @@ import copy
import warnings
from collections import MutableMapping
from importlib import import_module
from pprint import pformat
from scrapy.utils.deprecate import create_deprecated_class
from scrapy.exceptions import ScrapyDeprecationWarning
@ -388,6 +389,12 @@ class BaseSettings(MutableMapping):
settings = self.copy()
return settings._to_dict()
def _repr_pretty_(self, p, cycle):
if cycle:
p.text(repr(self))
else:
p.text(pformat(self.copy_to_dict()))
@property
def overrides(self):
warnings.warn("`Settings.overrides` attribute is deprecated and won't "