mirror of
https://github.com/python/cpython.git
synced 2025-08-03 00:23:06 +00:00
allow keyword args after *args in a function call
This commit is contained in:
parent
de0de885f7
commit
2d735bc098
6 changed files with 30 additions and 13 deletions
|
@ -284,6 +284,14 @@ class GrammarTests(unittest.TestCase):
|
|||
pos2key2dict(1,2,k2=100,tokwarg1=100,tokwarg2=200)
|
||||
pos2key2dict(1,2,tokwarg1=100,tokwarg2=200, k2=100)
|
||||
|
||||
# keyword arguments after *arglist
|
||||
def f(*args, **kwargs):
|
||||
return args, kwargs
|
||||
self.assertEquals(f(1, x=2, *[3, 4], y=5), ((1, 3, 4),
|
||||
{'x':2, 'y':5}))
|
||||
self.assertRaises(SyntaxError, eval, "f(1, *(2,3), 4)")
|
||||
self.assertRaises(SyntaxError, eval, "f(1, x=2, *(3,4), x=5)")
|
||||
|
||||
# argument annotation tests
|
||||
def f(x) -> list: pass
|
||||
self.assertEquals(f.__annotations__, {'return': list})
|
||||
|
|
|
@ -75,7 +75,7 @@ class KeywordOnlyArgTestCase(unittest.TestCase):
|
|||
|
||||
def testSyntaxErrorForFunctionCall(self):
|
||||
self.assertRaisesSyntaxError("f(p, k=1, p2)")
|
||||
self.assertRaisesSyntaxError("f(p, *(1,2), k1=100)")
|
||||
self.assertRaisesSyntaxError("f(p, k1=50, *(1,2), k1=100)")
|
||||
|
||||
def testRaiseErrorFuncallWithUnexpectedKeywordArgument(self):
|
||||
self.assertRaises(TypeError, keywordonly_sum, ())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue