Mercurial > hg-stable
diff mercurial/wireprotov2server.py @ 39996:582676acaf6d
wireprotov2: derive "required" from presence of default value
If we define a default value for all optional arguments, we no
longer need to explicitly declare whether the argument is required.
Instead, we can derive it from the presence of a default value
callable.
Differential Revision: https://phab.mercurial-scm.org/D4790
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Thu, 27 Sep 2018 09:23:17 -0700 |
parents | 7b752bf08435 |
children | c537144fdbef |
line wrap: on
line diff
--- a/mercurial/wireprotov2server.py Mon Oct 01 09:05:40 2018 -0700 +++ b/mercurial/wireprotov2server.py Thu Sep 27 09:23:17 2018 -0700 @@ -477,9 +477,6 @@ 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. - ``example`` An example value for this argument. @@ -535,13 +532,9 @@ raise error.ProgrammingError('%s argument for command %s does not ' 'declare example field' % (arg, name)) - if 'default' in meta and meta.get('required'): - raise error.ProgrammingError('%s argument for command %s is marked ' - 'as required but has a default value' % - (arg, name)) + meta['required'] = 'default' not in meta meta.setdefault('default', lambda: None) - meta.setdefault('required', False) meta.setdefault('validvalues', None) def register(func): @@ -570,14 +563,17 @@ args={ 'noderange': { 'type': 'list', + 'default': lambda: None, 'example': [[b'0123456...'], [b'abcdef...']], }, 'nodes': { 'type': 'list', + 'default': lambda: None, 'example': [b'0123456...'], }, 'nodesdepth': { 'type': 'int', + 'default': lambda: None, 'example': 10, }, 'fields': { @@ -746,7 +742,6 @@ }, 'nodes': { 'type': 'list', - 'required': True, 'example': [b'0123456...'], }, 'fields': { @@ -757,7 +752,6 @@ }, 'path': { 'type': 'bytes', - 'required': True, 'example': b'foo.txt', } }, @@ -848,7 +842,6 @@ args={ 'namespace': { 'type': 'bytes', - 'required': True, 'example': b'ns', }, }, @@ -865,7 +858,6 @@ args={ 'key': { 'type': 'bytes', - 'required': True, 'example': b'foo', }, }, @@ -883,7 +875,6 @@ args={ 'nodes': { 'type': 'list', - 'required': True, 'example': [b'0123456...'], }, 'haveparents': { @@ -899,7 +890,6 @@ }, 'tree': { 'type': 'bytes', - 'required': True, 'example': b'', }, }, @@ -956,22 +946,18 @@ args={ 'namespace': { 'type': 'bytes', - 'required': True, 'example': b'ns', }, 'key': { 'type': 'bytes', - 'required': True, 'example': b'key', }, 'old': { 'type': 'bytes', - 'required': True, 'example': b'old', }, 'new': { 'type': 'bytes', - 'required': True, 'example': 'new', }, },