No shipped stubs and using mypy
See original GitHub issueQuestion
It looks like default ONNX (both installed through pip and conda-forge) does not ship with stub files that mypy can use for typing types like TensorProto
, AttributeProto
, etc. *Proto
. Is there any way to generate them when using the library, or is this a bug?
When I tried using python setup.py develop
myself, it correctly generated the stubs (.pyi
s for all the protobuf modules), but it would be nice if this worked when installing through a manager. I tracked down that the cmake
generates the stubs with the ONNX_GEN_PB_TYPE_STUBS
flag:
https://github.com/onnx/onnx/blob/66480ce6ab0f4c56e27bb120f246c3ddd0d1e19e/CMakeLists.txt#L274-L296
However, they don’t seem to be generated on a default installation, and I’m not sure why.
System information
- OS Platform and Distribution: macOS Monterey 12.4
- ONNX version: 1.12.0
- Python version: 3.10.5
Further information
- Relevant Area: best practices
Notes
The main issue is that types like AttributeProto
end up as Any
, even though we know that they are concrete.
Additionally, information on what fields they have is lost.
# test.py
import onnx
reveal_type(onnx.helper.AttributeProto)
test.py:1: error: Skipping analyzing "onnx": module is installed, but missing library stubs or py.typed marker
test.py:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
test.py:3: note: Revealed type is "Any"
Found 1 error in 1 file (checked 1 source file)
Issue Analytics
- State:
- Created a year ago
- Comments:7 (7 by maintainers)
All good!
Sure. Just added. I can repro the issue you mentioned. The binary size (wheel) just increases by 5KB so adding your patch looks fine to me. Please review it again. Thanks!