MarcoGorelli / cython-lint

Lint Cython files
MIT License
68 stars 11 forks source link

Support IWYU checks in pyx files #81

Open vyasr opened 12 months ago

vyasr commented 12 months ago

Cython implicitly brings all cimport objects in a pxd file into the namespace of the corresponding pyx file. For example:

# foo.pxd
from lib.stdint cimport uint8_t

# foo.pyx
cdef f(uint8_t x):  # uint8_t is known because it's cimported in the pxd file
    pass

However, this can lead to inconsistent cimports across a package where some types are not cimported in the file that they are used. It would be helpful if cython-lint could raise an error in such cases.

Since I could imagine that approach not being favored by everyone, it would also be acceptable to have a configuration option that allows cython-lint to do the exact opposite and disallow any duplicate cimports between pyx and pxd files. Although not my preference, there may be some users of cython-lint with a preference for that. My first choice would be for cython-lint to be a more opinionated linter (a la black) in this situation, but I think the configuration approach would be an acceptable resolution as well. The truly undesirable case is when some cimports are present in both files while others are not, making it impossible to know a priori where to look.