Skip to content

Typehints derived from type comments not properly handled in generated signature and parameters #318

Closed
@fmigneault

Description

@fmigneault

When type hints are generated for class methods that provide the types using the comment annotation format, some cases are not handled correctly. (i.e.: using # type: (<args>) -> <return>)

  1. Base classes are replaced by the first argument from their corresponding __init__ call.
    For some reason, the Parameters section for the class' __init__ are not reported anywhere.
    (maybe because they are already processed as base class components, instead of self, so no more parameters to process?)
  2. Parameters in other methods have their types offset by one.

All this is most definitely caused by inspect.signature that does not include self or cls definitions, since they are not to be provided type comments definitions (similar to how the instance reference is automatically passed during the method call and must not be passed as argument).
Instead of inspect.siganture, one should use inspect.getfullargspec to obtain the full arguments derived from type comments, including self for methods or cls for classmethods.

Use cases are demonstrated in below images.

using autodoc_typehints = "description"

image

with autodoc_typehints disabled

image

corresponding code:

image

source code for reference: https://github.com/Ouranosinc/Magpie
and config: https://github.com/Ouranosinc/Magpie/blob/master/docs/conf.py

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions