From 291483dd39cb79e66cb9006cc033a35b889538e7 Mon Sep 17 00:00:00 2001 From: Aaron Wilson Date: Fri, 22 Nov 2019 20:39:45 +0000 Subject: [PATCH] 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. --- gunicorn/config.py | 9 +++++++++ tests/test_config.py | 7 +++++++ 2 files changed, 16 insertions(+) diff --git a/gunicorn/config.py b/gunicorn/config.py index 086725bd..f21f74f8 100644 --- a/gunicorn/config.py +++ b/gunicorn/config.py @@ -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,), {}) diff --git a/tests/test_config.py b/tests/test_config.py index 0587c63c..8b1922e6 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -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'])