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

Missing type annotation for maturin project #341

Open
benruijl opened this issue Apr 16, 2024 · 6 comments
Open

Missing type annotation for maturin project #341

benruijl opened this issue Apr 16, 2024 · 6 comments

Comments

@benruijl
Copy link

I am building a Python module from Rust using maturin. To include type information, I provide a .pyi file. The type information is properly handled when using Visual Studio Code for example, but when I try to generate docs with quartodoc I do not see any types for my function arguments and return values.

@machow
Copy link
Owner

machow commented Aug 20, 2024

It looks like griffe (which we use to look up type hints) supports .pyi files, so should find this information. I haven't tried looking up this kind of info yet, though, and will add a type stub to quartodoc to check!

mkdocstrings/griffe#77

@machow
Copy link
Owner

machow commented Aug 22, 2024

I've added a test that uses a stub file, and was able to see the type annotations in the stub. Do you mind checking whether the latest version of quartodoc, and upgrading griffe, find the annotations.

Here's the PR with the test:

@benruijl
Copy link
Author

I upgraded everything and I still don't see the annotations rendered. But maybe I misunderstand what the output should give?
Here is a screenshot:

image

For the function parse I added an explicit Parameters block and it shows the type that I provided in that block. For the function num, I didn't provide a block.

Both functions do not show any types. I would have expected:

Expression.num(_cls, num: float | int, relative_error:float =None)
Expression.parse(_cls, input: str)

@machow
Copy link
Owner

machow commented Aug 23, 2024

Ah, it sounds like you're saying the types aren't showing up in the call signature. Is that right? I don't think that's currently implemented, but is definitely worth enabling.

If that sounds right, I can use this issue to track implementing annotations in call signatures

@benruijl
Copy link
Author

Where would the type annotations currently be displayed? I believe the type in the Parameters block is parsed from the docstring? I haven't tried what happens if I omit the types in the docstring.

I would indeed love to see type annotations in the call signatures. You can reuse this issue, but you/I could also start a new one.

@machow
Copy link
Owner

machow commented Aug 23, 2024

If you omit the type in the Parameters section, it should fill it in based on the signature.

For example, something like...

def f(x: int):
    """A function.
    
    Parameters
    ------------
    x:
        The x parameter

    """

Should fill in that x is an int, based on the signature

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

No branches or pull requests

2 participants