MarcoGorelli / cython-lint

Lint Cython files
MIT License
69 stars 11 forks source link

Invalid defined but unused error #52

Closed stefanv closed 1 year ago

stefanv commented 1 year ago

I am not 100% sure whether this is a bug or not. Maybe cython-lint knows something about that pointer cast I don't.

Input:

def __getstate__():
    cdef np.intp_t size = cself.tree_buffer.size() * sizeof(ckdtreenode)
    cdef np.ndarray tree = np.asarray(<char[:size]> cself.tree_buffer.data())

    return tree

Output:

/tmp/foo.pyx:2:20: 'size' defined but unused
MarcoGorelli commented 1 year ago

looks like a bug, thanks for the report! 🙌

MarcoGorelli commented 1 year ago

OK, got it, it's that CythonArrayNode has a base_type_node attribute, but it doesn't appear in child_attrs, so it doesn't get traversed:

(Pdb) tree.body.body.stats[-1].expr.args[0]
<Cython.Compiler.ExprNodes.CythonArrayNode object at 0x7fce9077bb80>
(Pdb) tree.body.body.stats[-1].expr.args[0].child_attrs
['operand', 'shapes']
(Pdb) tree.body.body.stats[-1].expr.args[0].base_type_node
<Cython.Compiler.Nodes.MemoryViewSliceTypeNode object at 0x7fce9077bac0>

I'll report upstream, but for now I'll patch around it and make a new release