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 annotations in generic class description #10605

Closed
francois-rozet opened this issue Jun 26, 2022 · 8 comments
Closed

Missing type annotations in generic class description #10605

francois-rozet opened this issue Jun 26, 2022 · 8 comments

Comments

@francois-rozet
Copy link

francois-rozet commented Jun 26, 2022

Describe the bug

With autodoc_typehints = 'description', the parameter type annotations of the constructor (__init__) of generic classes are missing from the description.

How to Reproduce

With autodoc_typehints = 'description' in conf.py,

from typing import *

#: whatever
T = TypeVar('T')

class Dummy(Generic[T]):
    r"""
    Arguments:
        arg: missing type annotation
    """

    def __init__(self, arg: str):
        pass

results in

image

in which the type annotation is missing for the arg parameter.

Expected behavior

The type annotations should not be missing.

Your project

N/A

Screenshots

No response

OS

Ubuntu 20.04

Python version

3.8.10

Sphinx version

5.0.2

Sphinx extensions

sphinx.ext.autodoc

Extra tools

No response

Additional context

This issue is probably related to #8219 and #8142.

@robsdedude
Copy link

I came across a similar issue with autodoc_typehints = 'description'. I'm working on a PR that will fix this and my issue.

Basically, the resolution doesn't work for constructors when autodoc_typehints = 'description'. So something like

from __future__ import annotations

import typing as t

class Dummy():
    r"""
    Arguments:
        arg: missing type annotation
    """

    def __init__(self, arg: t.Optional[str]):
        pass

will also end up with a wrong type hint. In this case, it will be t.Optional[str] instead of Optional[str] which it'd be for other methods.

robsdedude added a commit to robsdedude/sphinx that referenced this issue Jul 29, 2022
Constructor annotations where not properly detected in autodoc when
`autodoc_typehints` was `'description'` or `'both'`.
robsdedude added a commit to robsdedude/sphinx that referenced this issue Jul 29, 2022
Constructor annotations where not properly detected in autodoc when
`autodoc_typehints` was `'description'` or `'both'`.
robsdedude added a commit to robsdedude/sphinx that referenced this issue Jul 29, 2022
Constructor annotations where not properly detected in autodoc when
`autodoc_typehints` was `'description'` or `'both'`.
robsdedude added a commit to robsdedude/sphinx that referenced this issue Jul 29, 2022
Constructor annotations where not properly detected in autodoc when
`autodoc_typehints` was `'description'` or `'both'`.
@francois-rozet
Copy link
Author

Hello @robsdedude, thanks for your PR, I hope it gets merged!

P.S. if you do a lot of rebase, avoid using issue identifiers in the commit message as it creates a lot of notifications 😅

@robsdedude
Copy link

Yeah, I just realized 🙈 I'm sorry.

robsdedude added a commit to robsdedude/sphinx that referenced this issue Sep 28, 2022
Constructor annotations where not properly detected in autodoc when
`autodoc_typehints` was `'description'` or `'both'`.
robsdedude added a commit to robsdedude/sphinx that referenced this issue Sep 28, 2022
Constructor annotations where not properly detected in autodoc when
`autodoc_typehints` was `'description'` or `'both'`.
@robsdedude
Copy link

robsdedude commented Sep 28, 2022

So sorry for the pings. I'll change the commit message now for good.

@AA-Turner
Copy link
Member

@francois-rozet is this now resolved?

@francois-rozet
Copy link
Author

francois-rozet commented Sep 2, 2023

Hello @AA-Turner, yes. I tried with a more recent version of Sphinx (6.1.3) and it seems to be resolved.

T = TypeVar('T')

class Dummy(Generic[T]):
    r"""Dummy class.

    Arguments:
        arg: missing type annotation
    """

    def __init__(self, arg: str):
        pass

results in

image

The type is not missing anymore.

@robsdedude
Copy link

@AA-Turner do you reckon it's worth splitting #10605 (comment) into a separate issue as it's not been resolved yet?

@AA-Turner
Copy link
Member

Please do!

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

No branches or pull requests

4 participants