MarcoGorelli / cython-lint

Lint Cython files
MIT License
68 stars 11 forks source link

false positive: imported but unused #70

Closed MarcoGorelli closed 1 year ago

MarcoGorelli commented 1 year ago

e.g. _sys here

https://github.com/pri1311/cupy/blob/master/cupy_backends/cuda/libs/cusparse.pyx#L1370

MarcoGorelli commented 1 year ago

I don't think much can be done here: if I have:

import sys as _sys  # no-cython-lint

IF 11010 <= CUPY_CUDA_VERSION < 12000:
    if _sys.platform == 'linux':
        _libname = 'libcusparse.so.11'
    else:
        _libname = 'cusparse64_11.dll'
ELSE:
    _libname = None

then all I get from astpretty is

 tree <Cython.Compiler.ModuleNode.ModuleNode object at 0x7f0e8d064e80> (<StringSourceDescriptor:t.pyx>, 1, 0)
     body <Cython.Compiler.Nodes.StatListNode object at 0x7f0e8d064b20> (<StringSourceDescriptor:t.pyx>, 1, 0)
         stats <Cython.Compiler.Nodes.StatListNode object at 0x7f0e8d064e20> (<StringSourceDescriptor:t.pyx>, 1, 7)
             stats <Cython.Compiler.Nodes.SingleAssignmentNode object at 0x7f0e8d064ee0> (<StringSourceDescriptor:t.pyx>, 1, 7)
                 rhs <Cython.Compiler.ExprNodes.ImportNode object at 0x7f0e8d064d60> (<StringSourceDescriptor:t.pyx>, 1, 7)
                     module_name <Cython.Compiler.ExprNodes.IdentifierStringNode object at 0x7f0e8d064a00> (<StringSourceDescriptor:t.pyx>, 1, 7)
                 lhs <Cython.Compiler.ExprNodes.NameNode object at 0x7f0e8d064e50> (<StringSourceDescriptor:t.pyx>, 1, 7)
         stats <Cython.Compiler.Nodes.SingleAssignmentNode object at 0x7f0e8d064190> (<StringSourceDescriptor:t.pyx>, 9, 15)
             rhs <Cython.Compiler.ExprNodes.NoneNode object at 0x7f0e8d064220> (<StringSourceDescriptor:t.pyx>, 9, 15)
             lhs <Cython.Compiler.ExprNodes.NameNode object at 0x7f0e8d064700> (<StringSourceDescriptor:t.pyx>, 9, 4)

So, I only get the symbols in lines 1 and 9 - those under the

IF 11010 <= CUPY_CUDA_VERSION < 12000:

don't get parsed

MarcoGorelli commented 1 year ago

I've asked about this on the Cython mailing list

MarcoGorelli commented 1 year ago

looks like this is deprecated syntax anyway

The DEF/IF etc. syntax is deprecated and users should employ C compile time mechanisms instead, so that the generated C files do not differ between platforms and environments. Or, they can use code generation on their side instead.

See https://github.com/cython/cython/issues/4310

closing then