Message309534
While debugging PyPy test failure on backports.lzma [1], I've noticed that PySequence_Check() on a dict type raises TypeError, e.g.:
Traceback (most recent call last):
File "test/test_lzma.py", line 273, in test_bad_args
b"", format=lzma.FORMAT_RAW, filters={})
File "/home/mgorny/git/backports.lzma/build/lib.linux-x86_64-3.6/backports/lzma/__init__.py", line 463, in decompress
decomp = LZMADecompressor(format, memlimit, filters)
TypeError: object of type 'dict' has no len()
The relevant C code is:
static int
parse_filter_chain_spec(lzma_filter filters[], PyObject *filterspecs)
{
Py_ssize_t i, num_filters;
num_filters = PySequence_Length(filterspecs);
...
where filterspecs is the object corresponding to the {} dict in Python snippet.
According to the documentation [2], PySequence_Length() should be 'equivalent to the Python expression len(o).' The Python expression obviously does not raise TypeError:
>>> len({})
0
Therefore, I think that the behavior of PySequence_Length() is a bug, and the function should successfully return the dict length instead.
[1]:https://github.com/peterjc/backports.lzma
[2]:https://docs.python.org/3/c-api/sequence.html#c.PySequence_Length |
|
Date |
User |
Action |
Args |
2018-01-06 00:38:27 | mgorny | set | recipients:
+ mgorny |
2018-01-06 00:38:27 | mgorny | set | messageid: <1515199107.36.0.467229070634.issue32500@psf.upfronthosting.co.za> |
2018-01-06 00:38:27 | mgorny | link | issue32500 messages |
2018-01-06 00:38:27 | mgorny | create | |
|