[Python-3000-checkins] r63379 - in python/branches/py3k: Lib/test/test_grammar.py Misc/NEWS Python/getargs.c

georg.brandl python-3000-checkins at python.org
Fri May 16 19:28:50 CEST 2008


Author: georg.brandl
Date: Fri May 16 19:28:50 2008
New Revision: 63379

Log:
#2895: don't crash with bytes as keyword argument names.


Modified:
   python/branches/py3k/Lib/test/test_grammar.py
   python/branches/py3k/Misc/NEWS
   python/branches/py3k/Python/getargs.c

Modified: python/branches/py3k/Lib/test/test_grammar.py
==============================================================================
--- python/branches/py3k/Lib/test/test_grammar.py	(original)
+++ python/branches/py3k/Lib/test/test_grammar.py	Fri May 16 19:28:50 2008
@@ -265,6 +265,14 @@
         d22v(*(1, 2, 3, 4))
         d22v(1, 2, *(3, 4, 5))
         d22v(1, *(2, 3), **{'d': 4})
+
+        # keyword argument type tests
+        try:
+            str('x', **{b'foo':1 })
+        except TypeError:
+            pass
+        else:
+            self.fail('Bytes should not work as keyword argument names')
         # keyword only argument tests
         def pos0key1(*, key): return key
         pos0key1(key=100)

Modified: python/branches/py3k/Misc/NEWS
==============================================================================
--- python/branches/py3k/Misc/NEWS	(original)
+++ python/branches/py3k/Misc/NEWS	Fri May 16 19:28:50 2008
@@ -12,6 +12,8 @@
 Core and Builtins
 -----------------
 
+- Issue 2895: Don't crash when given bytes objects as keyword names.
+
 - Issue 2798: When parsing arguments with PyArg_ParseTuple, the "s" code now
   allows any unicode string and returns a utf-8 encoded buffer, just like the
   "s#" code already does.  The "z" code was corrected as well.

Modified: python/branches/py3k/Python/getargs.c
==============================================================================
--- python/branches/py3k/Python/getargs.c	(original)
+++ python/branches/py3k/Python/getargs.c	Fri May 16 19:28:50 2008
@@ -1532,7 +1532,7 @@
 		while (PyDict_Next(keywords, &pos, &key, &value)) {
 			int match = 0;
 			char *ks;
-			if (!PyString_Check(key) && !PyUnicode_Check(key)) {
+			if (!PyUnicode_Check(key)) {
 				PyErr_SetString(PyExc_TypeError,
 					        "keywords must be strings");
 				return cleanreturn(0, freelist);


More information about the Python-3000-checkins mailing list