question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

No shipped stubs and using mypy

See original GitHub issue

Question

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 (.pyis 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:closed
  • Created a year ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
jbachurskicommented, Aug 9, 2022

All good!

0reactions
jcwchencommented, Aug 8, 2022

Would you consider applying the following patch in setup.py in your PR and check if it works for you as well?

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!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting started - mypy 0.991 documentation
The stubs are usually packaged in a distribution named types-<distribution> . Note that the distribution name may be different from the name of...
Read more >
Why isn't mypy seeing types from typeshed? - Stack Overflow
In the mypy docs on "Missing library stubs" it says: Mypy will not try inferring the types of any 3rd party libraries you...
Read more >
PEP 561 – Distributing and Packaging Type Information
However, there is no standard method to distribute packages with type information. Also, if one wished to ship stub files privately the only ......
Read more >
pandas-stubs · PyPI
The stubs are tested with mypy and pyright and are currently shipped with the Visual Studio Code extension pylance. Usage. Let's take this...
Read more >
python/typing - Gitter
I've used typing quite a bit within Zulip, so not the viewpoint you're looking for. ... Implementation for stubs: https://github.com/python/mypy/blob/ ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found