OpenCyphal / pydsdl

Cyphal DSDL processing front end implemented in Python
https://opencyphal.org
MIT License
11 stars 9 forks source link

Support mypy #70

Closed thirtytwobits closed 3 years ago

thirtytwobits commented 3 years ago

Your weird python import scheme in this project breaks any ability to use mypy when you depend on pydsdl. This seems like a pretty big miss for a project that is dedicated to datatypes; that you can't verify type safety.

pavel-kirienko commented 3 years ago

How do I reproduce this?

PyUAVCAN & Yakut depend on PyDSDL and use MyPy without issues.

thirtytwobits commented 3 years ago

Just remove the "ignore missing includes" in Nunavut's toxi.ini. I tried everything to get pydsdl typing to work last night and it was always looking for that type names as you rewrite them but not finding them because they are all actually named with underscores. Why is this so complicated in pydsdl?

pavel-kirienko commented 3 years ago

Just remove the "ignore missing includes" in Nunavut's toxi.ini.

Commenting out ignore_missing_imports = True here results in error: Skipping analyzing "pydsdl": found module but no type hints or library stubs, which is expected per the MyPy docs:

[mypy-pydsdl]
ignore_missing_imports = True

I tried everything to get pydsdl typing to work last night and it was always looking for that type names as you rewrite them but not finding them because they are all actually named with underscores. Why is this so complicated in pydsdl?

You lost me here. PyDSDL explicitly re-exports data types at the top-level module to prevent leakage of module internals into the public API context, which is a sensible thing to do (MyPy also has a helpful mode that allows one to enforce this: implicit_reexport = False, although it may not be quite relevant). This approach is superior to the alternative where the API exposes the internal structure of the package.

I don't understand how can this cause issues with MyPy. Can you share the exact output you are getting from MyPy?