Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python submodule to support IDE type hints #304

Open
ChristopherRabotin opened this issue May 24, 2024 · 9 comments
Open

Python submodule to support IDE type hints #304

ChristopherRabotin opened this issue May 24, 2024 · 9 comments

Comments

@ChristopherRabotin
Copy link
Member

IDEs don't know what's in the Python module. This can be solved by writing pyi files.

The goal of this task is to essentially repeat what Dora did here: dora-rs/dora#493 .

@cardigan1008
Copy link
Contributor

Hi @ChristopherRabotin , I'd like to give it a try. If it's convenient, please assign it to me.

@ChristopherRabotin
Copy link
Member Author

With pleasure! I briefly tried the script from the dora repo linked above, but it didn't work out of the box, and I don't know why. Let me know if you can figure it out, otherwise, I can probably tackle it in early September according to my current backlog on the three Nyx Space repos.

@ChristopherRabotin
Copy link
Member Author

@cardigan1008 , there's a new crate that aims to make this straight forward: PyO3/pyo3#2454 (comment) . I have not tried it, but it looks quite promising!

@cardigan1008
Copy link
Contributor

@cardigan1008 , there's a new crate that aims to make this straight forward: PyO3/pyo3#2454 (comment) . I have not tried it, but it looks quite promising!

Sounds great! Thanks for reminding. I’ll definitely give it a try soon.

@cardigan1008
Copy link
Contributor

Hi @ChristopherRabotin

Apologize for the delay in updating. I've just completed my project and have had the opportunity to try using pyo3-stub-gen. It turns out that some classes, such as LatestLeapSeconds, LeapSecondsFile, Ut1Provider, PyHifitimeError, PyDurationError, and PyParsingError, work well. However, there are some classes that don’t work as expected, primarily because pyo3-stub-gen fails to parse Duration into its own stub type.

The pyi file generated by pyo3-stub-gen can be found here.

@ChristopherRabotin
Copy link
Member Author

Hi there! No problem, this isn't a major rush. Good to know that it works in some cases but not others. Does the stub generator print an error when it fails by any chance? Thanks

@cardigan1008
Copy link
Contributor

Yes, when I tried to implement it for Duration. The error goes like this:

error[E0433]: failed to resolve: could not find `any` in `std`
  --> src/duration/mod.rs:69:32
   |
69 | #[cfg_attr(feature = "python", gen_stub_pyclass)]
   |                                ^^^^^^^^^^^^^^^^
   |                                |
   |                                could not find `any` in `std`
   |                                in this procedural macro expansion
   |
  ::: /home/yunboni/.cargo/registry/src/index.crates.io-6f17d22bba15001f/pyo3-stub-gen-derive-0.6.0/src/lib.rs:22:1
   |
22 | pub fn gen_stub_pyclass(_attr: TokenStream, item: TokenStream) -> TokenStream {
   | ----------------------------------------------------------------------------- in this expansion of `#[gen_stub_pyclass]`
   |
help: consider importing this struct
   |
11 + use std::any::TypeId;
   |

@ChristopherRabotin
Copy link
Member Author

Hi there,

Have you tried the recommended import that's shown in the compilation error?

Also, would it be possible for you to set up a PR with the changes the add the `gen_stub_pyclass? That way we can ensure that the type hints are built in the CI every time.

Thanks

@cardigan1008
Copy link
Contributor

Hi there,

Have you tried the recommended import that's shown in the compilation error?

Also, would it be possible for you to set up a PR with the changes the add the `gen_stub_pyclass? That way we can ensure that the type hints are built in the CI every time.

Thanks

I’ve tried the recommended import, but unfortunately, it still failed. It seems that the tool itself has some issues, and I’ve already proposed several issues regarding it. I’ll submit the PR to add the gen_stub_pyclass as soon as possible. However, please note that the PR may not cover all features.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants