I'm trying to fix mypy issues in scikit-learn (scikit-learn/scikit-learn#16726) and have a question/observation about C and Cython modules.
Say package has a _lib.pyx Cython extension, which defines a function _lib_func. The following passes mypy without errors,
from package._lib import _lib_func
however,
produces the following error,
error: Module 'package' has no attribute '_lib'
Are there any workaround for importing the complete C extension module and not only functions/classes it contains (short of using type: ignore at the import line)?
Example
Sorry I don't have a minimal reproducible example, I can make one if necessary. An actual example I run into,
sklearn/manifold/_barnes_hut_tsne.pyx Cython extension module.
- built as a C extension here
- that produces mypy error in import sklearn/manifold/tests/test_t_sne.py using,
from sklearn.manifold import _barnes_hut_tsne
with,
error: Module 'sklearn.manifold' has no attribute '_barnes_hut_tsne'
while importing individual functions from this C extension module works fine. And of course running this Python code also works fine.
Versions
- cpython: 3.8.0
- mypy : 0.770
- cython: 0.29.14
I'm trying to fix mypy issues in scikit-learn (scikit-learn/scikit-learn#16726) and have a question/observation about C and Cython modules.
Say
packagehas a_lib.pyxCython extension, which defines a function_lib_func. The following passes mypy without errors,however,
produces the following error,
Are there any workaround for importing the complete C extension module and not only functions/classes it contains (short of using
type: ignoreat the import line)?Example
Sorry I don't have a minimal reproducible example, I can make one if necessary. An actual example I run into,
sklearn/manifold/_barnes_hut_tsne.pyxCython extension module.Versions