mirror of
https://github.com/python/cpython.git
synced 2025-11-02 11:08:57 +00:00
#2895: don't crash with bytes as keyword argument names.
This commit is contained in:
parent
bf82e374ee
commit
d8b690f7ae
3 changed files with 11 additions and 1 deletions
|
|
@ -265,6 +265,14 @@ class GrammarTests(unittest.TestCase):
|
||||||
d22v(*(1, 2, 3, 4))
|
d22v(*(1, 2, 3, 4))
|
||||||
d22v(1, 2, *(3, 4, 5))
|
d22v(1, 2, *(3, 4, 5))
|
||||||
d22v(1, *(2, 3), **{'d': 4})
|
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
|
# keyword only argument tests
|
||||||
def pos0key1(*, key): return key
|
def pos0key1(*, key): return key
|
||||||
pos0key1(key=100)
|
pos0key1(key=100)
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,8 @@ What's new in Python 3.0b1?
|
||||||
Core and Builtins
|
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
|
- 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
|
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.
|
"s#" code already does. The "z" code was corrected as well.
|
||||||
|
|
|
||||||
|
|
@ -1532,7 +1532,7 @@ vgetargskeywords(PyObject *args, PyObject *keywords, const char *format,
|
||||||
while (PyDict_Next(keywords, &pos, &key, &value)) {
|
while (PyDict_Next(keywords, &pos, &key, &value)) {
|
||||||
int match = 0;
|
int match = 0;
|
||||||
char *ks;
|
char *ks;
|
||||||
if (!PyString_Check(key) && !PyUnicode_Check(key)) {
|
if (!PyUnicode_Check(key)) {
|
||||||
PyErr_SetString(PyExc_TypeError,
|
PyErr_SetString(PyExc_TypeError,
|
||||||
"keywords must be strings");
|
"keywords must be strings");
|
||||||
return cleanreturn(0, freelist);
|
return cleanreturn(0, freelist);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue