[Python-checkins] r45893 - in python/trunk: Lib/compiler/transformer.py Lib/test/test_compiler.py Misc/NEWS
georg.brandl
python-checkins at python.org
Wed May 3 20:18:33 CEST 2006
Author: georg.brandl
Date: Wed May 3 20:18:32 2006
New Revision: 45893
Modified:
python/trunk/Lib/compiler/transformer.py
python/trunk/Lib/test/test_compiler.py
python/trunk/Misc/NEWS
Log:
Bug #1385040: don't allow "def foo(a=1, b): pass" in the compiler package.
Modified: python/trunk/Lib/compiler/transformer.py
==============================================================================
--- python/trunk/Lib/compiler/transformer.py (original)
+++ python/trunk/Lib/compiler/transformer.py Wed May 3 20:18:32 2006
@@ -841,17 +841,15 @@
names.append(self.com_fpdef(node))
i = i + 1
- if i >= len(nodelist):
- break
-
- if nodelist[i][0] == token.EQUAL:
+ if i < len(nodelist) and nodelist[i][0] == token.EQUAL:
defaults.append(self.com_node(nodelist[i + 1]))
i = i + 2
elif len(defaults):
- # XXX This should be a syntax error.
- # Treat "(a=1, b)" as "(a=1, b=None)"
- defaults.append(Const(None))
+ # we have already seen an argument with default, but here
+ # came one without
+ raise SyntaxError, "non-default argument follows default argument"
+ # skip the comma
i = i + 1
return names, defaults, flags
Modified: python/trunk/Lib/test/test_compiler.py
==============================================================================
--- python/trunk/Lib/test/test_compiler.py (original)
+++ python/trunk/Lib/test/test_compiler.py Wed May 3 20:18:32 2006
@@ -56,6 +56,9 @@
def testYieldExpr(self):
compiler.compile("def g(): yield\n\n", "<string>", "exec")
+ def testDefaultArgs(self):
+ self.assertRaises(SyntaxError, compiler.parse, "def foo(a=1, b): pass")
+
def testLineNo(self):
# Test that all nodes except Module have a correct lineno attribute.
filename = __file__
Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS (original)
+++ python/trunk/Misc/NEWS Wed May 3 20:18:32 2006
@@ -91,6 +91,9 @@
Library
-------
+- Bug #1385040: don't allow "def foo(a=1, b): pass" in the compiler
+ package.
+
- Patch #1472854: make the rlcompleter.Completer class usable on non-
UNIX platforms.
More information about the Python-checkins
mailing list