Skip to content

Inconsistent behavior of fully qualified type hints. #351

@nikfilippas

Description

@nikfilippas

In conf.py I have set typehints_fully_qualified = False.
However, while most type hints adhere to this, there are some cases where they appear fully qualified for no apparent reason.

For example

def mass_translator(
        *,
        mass_in: Union[str, MassDef],
        mass_out: Union[str, MassDef],
        concentration: Union[str, Concentration]
) -> Callable[[Cosmology, Union[Real, NDArray], Real],
              Union[Real, NDArray]]:

gets interpreted as
Screenshot from 2023-04-28 11-22-04

while

def convert_concentration(
        cosmo: Cosmology,
        *,
        c_old: Union[Real, NDArray[Real]],
        Delta_old: Real,
        Delta_new: Real
) -> Union[float, NDArray[float]]:

looks alright
Screenshot from 2023-04-28 11-26-31

It also doesn't work well at all with numpy.typing.ArrayLike, as it always fully qualifies it:

-> ArrayLike

becomes
Screenshot from 2023-04-28 11-28-30

This is the rest of the config for autodoc and autodoc_typehints:

# Additional `autodoc` options.
autodoc_default_options = {
    "member-order": "bysource",
    "show-inheritance": True,
    "inherited-members": True,
    "special-members": "__call__",
}

# Options for `sphnix_autodoc_typehints`.
typehints_fully_qualified = False
typehints_defaults = "braces"
typehints_document_rtype = False
typehints_use_signature_return = True

I use Sphinx 6.2.1 and Python 3.11 on Ubuntu 22.04 LTS.
sphinx_autodoc_typehints.__version__ = '1.21.8'.

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