mirror of https://github.com/scrapy/scrapy.git
Remove __str__ and __repr__ from settings, introduce copy_to_dict() instead
Settings instances as dict's are easier to print or pretty print in the shell Fixes #1732
This commit is contained in:
parent
a35aec71e9
commit
a1ebff83d3
|
|
@ -368,11 +368,25 @@ class BaseSettings(MutableMapping):
|
|||
def __len__(self):
|
||||
return len(self.attributes)
|
||||
|
||||
def __str__(self):
|
||||
return str(self.attributes)
|
||||
def _to_dict(self):
|
||||
return {k: (v._to_dict() if isinstance(v, BaseSettings) else v)
|
||||
for k, v in six.iteritems(self)}
|
||||
|
||||
def __repr__(self):
|
||||
return "<%s %s>" % (self.__class__.__name__, self.attributes)
|
||||
def copy_to_dict(self):
|
||||
"""
|
||||
Make a copy of current settings and convert to a dict.
|
||||
|
||||
This method returns a new dict populated with the same values
|
||||
and their priorities as the current settings.
|
||||
|
||||
Modifications to the returned dict won't be reflected on the original
|
||||
settings.
|
||||
|
||||
This method can be useful for example for printing settings
|
||||
in Scrapy shell.
|
||||
"""
|
||||
settings = self.copy()
|
||||
return settings._to_dict()
|
||||
|
||||
@property
|
||||
def overrides(self):
|
||||
|
|
|
|||
Loading…
Reference in New Issue