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

.. py:data:: :type: option does not correctly link to type supplied #9899

Closed
kdschlosser opened this issue Nov 28, 2021 · 3 comments
Closed

Comments

@kdschlosser
Copy link

kdschlosser commented Nov 28, 2021

Describe the bug

when using the .. py:data:: directive there is the :type: option to specify the type for the data being stored in the module level attribute. It does not work within the context of the module. What I mean by that is I have to key out the entire module path and the class for the type instead of importing the type into the module and only having to type in the type class name.

How to Reproduce

say I have the following in the module "my_library.module1"

"""
.. py:data:: mol
    :type: Unit
    :value: 'mol'

    mole
"""

from .module2 import Unit

mol = Unit('mol')

The output I get when building the docs is this.

mol: Unit = 'mol'

    mole

and "Unit" is not a clickable link.

However if I have the following in the module "my_library.module1"

"""
.. py:data:: mol
    :type: my_library.module2.Unit
    :value: 'mol'

    mole
"""

from .module2 import Unit

mol = Unit('mol')

I get this for an output

mol: my_library.module2.Unit = 'mol'

    mole

and "my_library.module2.Unit" is a clickable link that brings up the documentation for the Unit class

Expected behavior

to be able to do the following

"""
.. py:data:: mol
    :type: Unit
    :value: 'mol'

    mole
"""

from .module2 import Unit

mol = Unit('mol')

and have the output be

mol: Unit = 'mol'

    mole

and "Unit" be a clickable link that leads to the class that is specified in :type:

Your project

https://github.com/kdschlosser/python-utils/tree/unit_conversion

Screenshots

No response

OS

Windows

Python version

3.8

Sphinx version

4.2

Sphinx extensions

sphinx.ext.autodoc

Extra tools

No response

Additional context

No response

@kdschlosser
Copy link
Author

kdschlosser commented Nov 28, 2021

I did also want to mention the use of :py:class:Unit does not work in the :type: option field.
Yet it does work when specifying the type for a parameter of a function.

I have also placed the import of "Unit" before the docstring and explicitly set the docstring to doc and that did not work either.

@tk0miya
Copy link
Member

tk0miya commented Nov 28, 2021

Reproduced with this:

.. py:module:: my_library.module2

.. py:class:: Unit

.. py:module:: my_library.module1

.. py:data:: mol
   :type: Unit
   :value: 'mol'

   mole

In this case, :py:class:`Unit` inside my_library.module1 module is also not working because its module is different with my_library.module2. :py:class:`.Unit` is working. But :type: field does not allow .Unit notation. So this must be a bug.

@tk0miya tk0miya added this to the 4.4.0 milestone Nov 28, 2021
tk0miya added a commit to tk0miya/sphinx that referenced this issue Nov 28, 2021
tk0miya added a commit that referenced this issue Nov 29, 2021
…r_in_typefield

Fix #9899: py domain: Allows cross-reference specifier to :type: option
@kdschlosser
Copy link
Author

Man o Man you are fast. Thanks for fixing this so it will work properly.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 30, 2021
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

2 participants