Issue #18896: Python function can now have more than 255 parameters.

collections.namedtuple() now supports tuples with more than 255 elements.
This commit is contained in:
Serhiy Storchaka 2016-12-16 19:19:02 +02:00
parent 14d8b9693b
commit 5bb8b9134b
10 changed files with 33 additions and 49 deletions

View file

@ -51,24 +51,12 @@ class KeywordOnlyArgTestCase(unittest.TestCase):
self.assertRaisesSyntaxError("def f(p, *, (k1, k2), **kw):\n pass\n")
def testSyntaxForManyArguments(self):
fundef = "def f("
for i in range(255):
fundef += "i%d, "%i
fundef += "*, key=100):\n pass\n"
self.assertRaisesSyntaxError(fundef)
fundef2 = "def foo(i,*,"
for i in range(255):
fundef2 += "i%d, "%i
fundef2 += "lastarg):\n pass\n"
self.assertRaisesSyntaxError(fundef2)
# exactly 255 arguments, should compile ok
fundef3 = "def f(i,*,"
for i in range(253):
fundef3 += "i%d, "%i
fundef3 += "lastarg):\n pass\n"
compile(fundef3, "<test>", "single")
# more than 255 positional arguments, should compile ok
fundef = "def f(%s):\n pass\n" % ', '.join('i%d' % i for i in range(300))
compile(fundef, "<test>", "single")
# more than 255 keyword-only arguments, should compile ok
fundef = "def f(*, %s):\n pass\n" % ', '.join('i%d' % i for i in range(300))
compile(fundef, "<test>", "single")
def testTooManyPositionalErrorMessage(self):
def f(a, b=None, *, c=None):