D4617: wireprotov2: always set "default" and "required" keys
indygreg (Gregory Szorc)
phabricator at mercurial-scm.org
Mon Sep 17 21:24:41 UTC 2018
indygreg created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.
REVISION SUMMARY
This makes call sites simpler since they won't have to deal with
missing keys.
REPOSITORY
rHG Mercurial
REVISION DETAIL
https://phab.mercurial-scm.org/D4617
AFFECTED FILES
mercurial/wireprotov2server.py
CHANGE DETAILS
diff --git a/mercurial/wireprotov2server.py b/mercurial/wireprotov2server.py
--- a/mercurial/wireprotov2server.py
+++ b/mercurial/wireprotov2server.py
@@ -362,7 +362,7 @@
', '.join(sorted(extra)))
# And look for required arguments that are missing.
- missing = {a for a in args if args[a].get('required')} - set(self._args)
+ missing = {a for a in args if args[a]['required']} - set(self._args)
if missing:
raise error.WireprotoCommandError(
@@ -374,7 +374,7 @@
for k, meta in sorted(args.items()):
# This argument wasn't passed by the client.
if k not in self._args:
- data[k] = meta.get('default', lambda: None)()
+ data[k] = meta['default']()
continue
v = self._args[k]
@@ -543,7 +543,8 @@
or ``bool``.
``default``
- A callable returning the default value for this argument.
+ A callable returning the default value for this argument. If not
+ specified, ``None`` will be the default value.
``required``
Bool indicating whether the argument is required.
@@ -600,6 +601,9 @@
raise error.ProgrammingError('%s argument for command %s does not '
'declare example field' % (arg, name))
+ meta.setdefault('default', lambda: None)
+ meta.setdefault('required', False)
+
def register(func):
if name in COMMANDS:
raise error.ProgrammingError('%s command already registered '
To: indygreg, #hg-reviewers
Cc: mercurial-devel
More information about the Mercurial-devel
mailing list