diff -r d72d5c942232 Lib/test/test_syntax.py --- a/Lib/test/test_syntax.py Thu Sep 01 21:38:37 2011 +0200 +++ b/Lib/test/test_syntax.py Fri Sep 02 23:56:38 2011 +0200 @@ -144,70 +144,6 @@ >>> f((x for x in L), 1) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] ->>> f(i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, -... i12, i13, i14, i15, i16, i17, i18, i19, i20, i21, i22, -... i23, i24, i25, i26, i27, i28, i29, i30, i31, i32, i33, -... i34, i35, i36, i37, i38, i39, i40, i41, i42, i43, i44, -... i45, i46, i47, i48, i49, i50, i51, i52, i53, i54, i55, -... i56, i57, i58, i59, i60, i61, i62, i63, i64, i65, i66, -... i67, i68, i69, i70, i71, i72, i73, i74, i75, i76, i77, -... i78, i79, i80, i81, i82, i83, i84, i85, i86, i87, i88, -... i89, i90, i91, i92, i93, i94, i95, i96, i97, i98, i99, -... i100, i101, i102, i103, i104, i105, i106, i107, i108, -... i109, i110, i111, i112, i113, i114, i115, i116, i117, -... i118, i119, i120, i121, i122, i123, i124, i125, i126, -... i127, i128, i129, i130, i131, i132, i133, i134, i135, -... i136, i137, i138, i139, i140, i141, i142, i143, i144, -... i145, i146, i147, i148, i149, i150, i151, i152, i153, -... i154, i155, i156, i157, i158, i159, i160, i161, i162, -... i163, i164, i165, i166, i167, i168, i169, i170, i171, -... i172, i173, i174, i175, i176, i177, i178, i179, i180, -... i181, i182, i183, i184, i185, i186, i187, i188, i189, -... i190, i191, i192, i193, i194, i195, i196, i197, i198, -... i199, i200, i201, i202, i203, i204, i205, i206, i207, -... i208, i209, i210, i211, i212, i213, i214, i215, i216, -... i217, i218, i219, i220, i221, i222, i223, i224, i225, -... i226, i227, i228, i229, i230, i231, i232, i233, i234, -... i235, i236, i237, i238, i239, i240, i241, i242, i243, -... i244, i245, i246, i247, i248, i249, i250, i251, i252, -... i253, i254, i255) -Traceback (most recent call last): -SyntaxError: more than 255 arguments - -The actual error cases counts positional arguments, keyword arguments, -and generator expression arguments separately. This test combines the -three. - ->>> f(i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, -... i12, i13, i14, i15, i16, i17, i18, i19, i20, i21, i22, -... i23, i24, i25, i26, i27, i28, i29, i30, i31, i32, i33, -... i34, i35, i36, i37, i38, i39, i40, i41, i42, i43, i44, -... i45, i46, i47, i48, i49, i50, i51, i52, i53, i54, i55, -... i56, i57, i58, i59, i60, i61, i62, i63, i64, i65, i66, -... i67, i68, i69, i70, i71, i72, i73, i74, i75, i76, i77, -... i78, i79, i80, i81, i82, i83, i84, i85, i86, i87, i88, -... i89, i90, i91, i92, i93, i94, i95, i96, i97, i98, i99, -... i100, i101, i102, i103, i104, i105, i106, i107, i108, -... i109, i110, i111, i112, i113, i114, i115, i116, i117, -... i118, i119, i120, i121, i122, i123, i124, i125, i126, -... i127, i128, i129, i130, i131, i132, i133, i134, i135, -... i136, i137, i138, i139, i140, i141, i142, i143, i144, -... i145, i146, i147, i148, i149, i150, i151, i152, i153, -... i154, i155, i156, i157, i158, i159, i160, i161, i162, -... i163, i164, i165, i166, i167, i168, i169, i170, i171, -... i172, i173, i174, i175, i176, i177, i178, i179, i180, -... i181, i182, i183, i184, i185, i186, i187, i188, i189, -... i190, i191, i192, i193, i194, i195, i196, i197, i198, -... i199, i200, i201, i202, i203, i204, i205, i206, i207, -... i208, i209, i210, i211, i212, i213, i214, i215, i216, -... i217, i218, i219, i220, i221, i222, i223, i224, i225, -... i226, i227, i228, i229, i230, i231, i232, i233, i234, -... i235, i236, i237, i238, i239, i240, i241, i242, i243, -... (x for x in i244), i245, i246, i247, i248, i249, i250, i251, -... i252=1, i253=1, i254=1, i255=1) -Traceback (most recent call last): -SyntaxError: more than 255 arguments - >>> f(lambda x: x[0] = 3) Traceback (most recent call last): SyntaxError: lambda cannot contain assignment diff -r d72d5c942232 Python/ast.c --- a/Python/ast.c Thu Sep 01 21:38:37 2011 +0200 +++ b/Python/ast.c Fri Sep 02 23:56:38 2011 +0200 @@ -2433,11 +2433,6 @@ return NULL; } - if (nargs + nkeywords + ngens > 255) { - ast_error(n, "more than 255 arguments"); - return NULL; - } - args = asdl_seq_new(nargs + ngens, c->c_arena); if (!args) return NULL; diff -r d72d5c942232 Python/compile.c --- a/Python/compile.c Thu Sep 01 21:38:37 2011 +0200 +++ b/Python/compile.c Fri Sep 02 23:56:38 2011 +0200 @@ -2755,21 +2755,65 @@ expr_ty starargs, expr_ty kwargs) { + int i = 0; int code = 0; - - n += asdl_seq_LEN(args); - VISIT_SEQ(c, expr, args); + int n_posargs = asdl_seq_LEN(args); + int n_kwargs = -1; + + if (n_posargs <= 255) { + n += asdl_seq_LEN(args); + VISIT_SEQ(c, expr, args); + } if (keywords) { - VISIT_SEQ(c, keyword, keywords); - n |= asdl_seq_LEN(keywords) << 8; + n_kwargs = asdl_seq_LEN(keywords); + if (n_kwargs <= 255) { + VISIT_SEQ(c, keyword, keywords); + n |= n_kwargs << 8; + } + } + if (n_posargs > 255) { + /* More than 255 positional arguments, pass them as starargs list. */ + VISIT_SEQ(c, expr, args); + ADDOP_I(c, BUILD_LIST, n_posargs); + code |= 1; } if (starargs) { VISIT(c, expr, starargs); + if (n_posargs > 255) { + /* There is already a list with positional arguments on TOS, + extend the list with the starargs list. */ + ADDOP(c, INPLACE_ADD); + } code |= 1; } + if (n_kwargs > 255) { + /* More than 255 keyword arguments, pass them using a kwargs + dictionary. */ + ADDOP_I(c, BUILD_MAP, n_kwargs); + for (i = 0; i < n_kwargs; ++i) { + keyword_ty kw = (keyword_ty)asdl_seq_GET(keywords, i); + VISIT(c, expr, kw->value); + ADDOP_O(c, LOAD_CONST, kw->arg, consts); + ADDOP(c, STORE_MAP); + } + code |= 2; + } if (kwargs) { - VISIT(c, expr, kwargs); - code |= 2; + if (n_kwargs > 255) { + /* There is already a dict with keyword arguments on TOS, + merge in the kwargs dict. */ + PyObject *update_str = PyUnicode_FromString("update"); + if (!update_str) + return 0; + ADDOP(c, DUP_TOP); + ADDOP_O(c, LOAD_ATTR, update_str, names); + VISIT(c, expr, kwargs); + ADDOP_I(c, CALL_FUNCTION, 1); + ADDOP(c, POP_TOP); + } else { + VISIT(c, expr, kwargs); + code |= 2; + } } switch (code) { case 0: