# HG changeset patch # User Pierre-Yves David # Date 2021-01-13 17:29:19 # Node ID b9b37418ac7e167fa8c7e59cae8ef6bfda906f5a # Parent e8b0c519dfb3d33592daeab2ce96624b58396afc ui: add a "config_default" method This allow code to access the expected value for a config. This is useful in the context of dynamic default value, and short term it will be useful to write dynamically "correct" code. Differential Revision: https://phab.mercurial-scm.org/D9759 diff --git a/mercurial/ui.py b/mercurial/ui.py --- a/mercurial/ui.py +++ b/mercurial/ui.py @@ -673,6 +673,18 @@ class ui(object): ) return value + def config_default(self, section, name): + """return the default value for a config option + + The default is returned "raw", for example if it is a callable, the + callable was not called. + """ + item = self._knownconfig.get(section, {}).get(name) + + if item is None: + raise KeyError((section, name)) + return item.default + def configsuboptions(self, section, name, default=_unset, untrusted=False): """Get a config option and all sub-options.