Add a __repr__ to config to include its value (#2076)

It's sometimes helpful to be able to trivially dump all the config values
for debugging purposes. This commit defines a repr for that.
This commit is contained in:
Aaron Wilson 2019-11-22 20:39:45 +00:00 committed by Benoit Chesneau
parent 1aa9cf0529
commit 291483dd39
2 changed files with 16 additions and 0 deletions

View File

@ -308,6 +308,15 @@ class Setting(object):
self.order < other.order)
__cmp__ = __lt__
def __repr__(self):
return "<%s.%s object at %x with value %r>" % (
self.__class__.__module__,
self.__class__.__name__,
id(self),
self.value,
)
Setting = SettingMeta('Setting', (Setting,), {})

View File

@ -435,3 +435,10 @@ def test_bind_fd():
with AltArgs(["prog_name", "-b", "fd://42"]):
app = NoConfigApp()
assert app.cfg.bind == ["fd://42"]
def test_repr():
c = config.Config()
c.set("workers", 5)
assert "with value 5" in repr(c.settings['workers'])