Use pyo3 experimental-inspect instead of `generate_stubs.py`
Currently dora use a custom script called generate_stubs.py to generate type hinting in python.
Unfortunately, this typing is not perfect as it requires manual type hinting and has many depreciated feature when linted with:
uvx ruff check --select UP
We can try to run pyo3 with the feature flag experimental-inspect and see if this can be a good automatic stub generator.
To do this, we just need to replace in Cargo.toml:
pyo3 = { version = "0.23", features = [
"eyre",
"abi3-py37",
"multiple-pymethods",
] }
with:
pyo3 = { version = "0.23", features = [
"eyre",
"abi3-py37",
"multiple-pymethods",
"experimental-inspect"
] }
Hey, I was just working on this issue. Could you clarify how I can check if the issue is resolved after making the changes? That would be really helpful in troubleshooting.
So, basically, if this functionality work, you should be able to see type information as well as documentation within python inspection: https://stackoverflow.com/questions/37288135/inspect-module-for-python that is not based on our current __init__.pyi . You can delete the __init__.pyi reinstall using maturin develop to see if you see any difference.
I believe it's still not working. I made the necessary changes and followed the steps you provided, but I’m still encountering an error when inspecting it.
OK thanks for trying :S
@haixuanTao I have been thinking that after adding "experimental-inspect" to cargo.toml and removing generate_stub.py should I need to make changes in code of binaries/cli/src/lib.rs(or any other file). Please guide me!
No, the experimental-inspect is only for dora-node-api-python.
@haixuanTao
- I Added the experimental-inspect feature to PyO3 in
Cargo.toml:
pyo3 = { version = "0.23", features = [
"eyre",
"abi3-py37",
"multiple-pymethods",
"experimental-inspect"
] }
- and
async = ["pyo3/experimental-async", "pyo3/experimental-inspect"]inapis/python/node - Built the project with this feature enabled
- Created a test script to check if type annotations were accessible through Python's inspection mechanisms
- Attempted to generate improved stubs using the type information
Conclusions
- The experimental-inspect feature doesn't appear to expose type annotations through Python's standard inspection mechanisms
- No
__pyo3_annotations__attributes were found on any classes or functions - All classes had empty annotations dictionaries
- The generated stubs still lack proper type information
Class: DoraStatus
Class annotations: {}
Class: Enum
Class annotations: {}
Method: __new__
Signature: (cls, value)
Annotations: {}
Class: Node
Class annotations: {}
Class: Ros2Context
Class annotations: {}
Class: Ros2Durability
Class annotations: {}
Class: Ros2Liveliness
Class annotations: {}
Class: Ros2Node
Class annotations: {}
Class: Ros2NodeOptions
Class annotations: {}
Class: Ros2Publisher
Class annotations: {}
Class: Ros2QosPolicies
Class annotations: {}
Class: Ros2Subscription
Class annotations: {}
Class: Ros2Topic
Class annotations: {}
Ah okay. it's bummer. Thanks for this anyway