summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2008-05-16 17:28:50 (GMT)
committerGeorg Brandl <georg@python.org>2008-05-16 17:28:50 (GMT)
commitd8b690f7ae57169d95f1cb4b3a0bccf5adfe6a30 (patch)
tree7399049dc820af415adf247fffd25bbc2ee2aebc
parentbf82e374ee737992235cbe944c9ddbd58236a892 (diff)
downloadcpython-d8b690f7ae57169d95f1cb4b3a0bccf5adfe6a30.zip
cpython-d8b690f7ae57169d95f1cb4b3a0bccf5adfe6a30.tar.gz
cpython-d8b690f7ae57169d95f1cb4b3a0bccf5adfe6a30.tar.bz2
#2895: don't crash with bytes as keyword argument names.
-rw-r--r--Lib/test/test_grammar.py8
-rw-r--r--Misc/NEWS2
-rw-r--r--Python/getargs.c2
3 files changed, 11 insertions, 1 deletions
diff --git a/Lib/test/test_grammar.py b/Lib/test/test_grammar.py
index 4c0eda5..94b7b31 100644
--- a/Lib/test/test_grammar.py
+++ b/Lib/test/test_grammar.py
@@ -265,6 +265,14 @@ class GrammarTests(unittest.TestCase):
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)
diff --git a/Misc/NEWS b/Misc/NEWS
index 7bb3b3f..f39563a 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,8 @@ What's new in Python 3.0b1?
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.
diff --git a/Python/getargs.c b/Python/getargs.c
index 427a951..7ca7672 100644
--- a/Python/getargs.c
+++ b/Python/getargs.c
@@ -1532,7 +1532,7 @@ vgetargskeywords(PyObject *args, PyObject *keywords, const char *format,
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);