Skip to content

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

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

Paul Tremberth268e912273dc
diff --git a/scrapy/settings/__init__.py b/scrapy/settings/__init__.py
index 918bfc1e5..7b7808959 100644
--- a/scrapy/settings/__init__.py
+++ b/scrapy/settings/__init__.py
@@ -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 "