Patchwork [1,of,9] parser: verify excessive number of args excluding kwargs in buildargsdict()

login
register
mail settings
Submitter Yuya Nishihara
Date April 12, 2017, 3:53 p.m.
Message ID <350eec8e79a37c58dc56.1492012397@mimosa>
Download mbox | patch
Permalink /patch/20132/
State Accepted
Headers show

Comments

Yuya Nishihara - April 12, 2017, 3:53 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1491649657 -32400
#      Sat Apr 08 20:07:37 2017 +0900
# Node ID 350eec8e79a37c58dc56059d1cafee10a66b8aef
# Parent  f7b3677f66cd94fa01f345f6ab35229264aed179
parser: verify excessive number of args excluding kwargs in buildargsdict()

This makes the next patch slightly simpler. We don't need to check the
excessive number of keyword arguments since unknown and duplicated kwargs
are rejected.

Patch

diff --git a/mercurial/parser.py b/mercurial/parser.py
--- a/mercurial/parser.py
+++ b/mercurial/parser.py
@@ -135,8 +135,9 @@  def buildargsdict(trees, funcname, argsp
         raise error.ParseError(_("%(func)s takes at least %(nargs)d positional "
                                  "arguments")
                                % {'func': funcname, 'nargs': len(poskeys)})
-    if not varkey and len(trees) > len(poskeys) + len(keys):
-        raise error.ParseError(_("%(func)s takes at most %(nargs)d arguments")
+    if not varkey and kwstart > len(poskeys) + len(keys):
+        raise error.ParseError(_("%(func)s takes at most %(nargs)d positional "
+                                 "arguments")
                                % {'func': funcname,
                                   'nargs': len(poskeys) + len(keys)})
     args = {}
diff --git a/tests/test-revset.t b/tests/test-revset.t
--- a/tests/test-revset.t
+++ b/tests/test-revset.t
@@ -454,7 +454,7 @@  keyword arguments
   0
 
   $ log 'extra(branch, a, b)'
-  hg: parse error: extra takes at most 2 arguments
+  hg: parse error: extra takes at most 2 positional arguments
   [255]
   $ log 'extra(a, label=b)'
   hg: parse error: extra got multiple values for keyword argument 'label'