mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
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:
parent
14d8b9693b
commit
5bb8b9134b
10 changed files with 33 additions and 49 deletions
|
@ -319,8 +319,7 @@ class TestNamedTuple(unittest.TestCase):
|
|||
self.assertEqual(Dot(1)._replace(d=999), (999,))
|
||||
self.assertEqual(Dot(1)._fields, ('d',))
|
||||
|
||||
# n = 5000
|
||||
n = 254 # SyntaxError: more than 255 arguments:
|
||||
n = 5000
|
||||
names = list(set(''.join([choice(string.ascii_letters)
|
||||
for j in range(10)]) for i in range(n)))
|
||||
n = len(names)
|
||||
|
|
|
@ -401,16 +401,9 @@ if 1:
|
|||
self.assertNotIn((Ellipsis, Ellipsis), d)
|
||||
|
||||
def test_annotation_limit(self):
|
||||
# 16 bits are available for # of annotations, but only 8 bits are
|
||||
# available for the parameter count, hence 255
|
||||
# is the max. Ensure the result of too many annotations is a
|
||||
# SyntaxError.
|
||||
# more than 255 annotations, should compile ok
|
||||
s = "def f(%s): pass"
|
||||
s %= ', '.join('a%d:%d' % (i,i) for i in range(256))
|
||||
self.assertRaises(SyntaxError, compile, s, '?', 'exec')
|
||||
# Test that the max # of annotations compiles.
|
||||
s = "def f(%s): pass"
|
||||
s %= ', '.join('a%d:%d' % (i,i) for i in range(255))
|
||||
s %= ', '.join('a%d:%d' % (i,i) for i in range(300))
|
||||
compile(s, '?', 'exec')
|
||||
|
||||
def test_mangling(self):
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -926,7 +926,7 @@ class SizeofTest(unittest.TestCase):
|
|||
def inner():
|
||||
return x
|
||||
return inner
|
||||
check(get_cell2.__code__, size('6i13P') + 1)
|
||||
check(get_cell2.__code__, size('6i13P') + calcsize('n'))
|
||||
# complex
|
||||
check(complex(0,1), size('2d'))
|
||||
# method_descriptor (descriptor object)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue