Mercurial > hg
comparison mercurial/ui.py @ 33150:77e666f943a6
configitems: support callable as a default value
Yuya pointed out that using mutable value as the default could be problematic.
To work around this we now support callable object as default value. This
allows for creating new mutable objects on demand when needed.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Wed, 28 Jun 2017 13:50:20 +0200 |
parents | d9962854a4a2 |
children | e714159860fd |
comparison
equal
deleted
inserted
replaced
33149:a14e2e7f7d1f | 33150:77e666f943a6 |
---|---|
453 else: | 453 else: |
454 item = self._knownconfig.get(section, {}).get(name) | 454 item = self._knownconfig.get(section, {}).get(name) |
455 if default is _unset: | 455 if default is _unset: |
456 if item is None: | 456 if item is None: |
457 value = default | 457 value = default |
458 elif callable(item.default): | |
459 value = item.default() | |
458 else: | 460 else: |
459 value = item.default | 461 value = item.default |
460 elif item is not None: | 462 elif item is not None: |
461 msg = ("specifying a default value for a registered " | 463 msg = ("specifying a default value for a registered " |
462 "config item: '%s.%s' '%s'") | 464 "config item: '%s.%s' '%s'") |