STINNER Victor added the comment:
Serhiy Storchaka: "The assertion was valid while all keywords did came from a
constant keywords tuple in CALL_FUNCTION_KW. But if the FASTCALL protocol is
extended for var-keyword arguments, keywords can be arbitrary and the assertion
can fail. The assertion on the next line can fail too."
The second _PyStack_AsDict() assertion is:
assert(PyDict_GetItem(kwdict, key) == NULL);
This assertion fails if kwnames (tuple) argument of _PyStack_AsDict() contains
duplicated keys, or at least two keys which have the same hash value and are
equal.
If someone pass kwnames with duplicates keys on purpose (for whatever) reasons,
the assertion fails. I'm not sure that the assertion makes sense since it's a
feature of Python to be able to replace dictionary values:
>>> def func(**kw): print(kw)
...
>>> func(**{'x': 1, 'x': 2})
{'x': 2}
>>> {'x': 1, 'x': 2}
{'x': 2}
Are you suggesting to remove "assert(PyDict_GetItem(kwdict, key) == NULL);" too?
Note: In Python 3.6, CALL_FUNCTION_EX already uses FASTCALL for C functions
using METH_FASTCALL. In this case, _PyCFunction_FastCallDict() uses
_PyStack_UnpackDict(). For example, open() already uses METH_FASTCALL in Python
3.6. In there an issue with _PyStack_UnpackDict()? (I don't think so.)
----------
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue29360>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com