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

autodoc_type_aliases fails to replace union subtype with dots #13229

Open
ej-toita opened this issue Jan 10, 2025 · 3 comments
Open

autodoc_type_aliases fails to replace union subtype with dots #13229

ej-toita opened this issue Jan 10, 2025 · 3 comments
Labels
awaiting:response Waiting for a response from the author of this issue extensions:autodoc type:bug

Comments

@ej-toita
Copy link

ej-toita commented Jan 10, 2025

Describe the bug

autodoc_type_aliases shows weird behavior when a function contains union of aliased type and other type.

How to Reproduce

minimum.py

from __future__ import annotations


class Alias:
    alias = int


def func(
    arg1: Alias.alias,
    arg2: Alias.alias,
) -> Alias.alias:
    """expected behavior.
    `Alias.alias` is replaced to `alias`.
    """
    return 1


def func_buggy(
    arg1: Alias.alias,
    arg2: Alias.alias | str,
) -> Alias.alias:
    """types,
    including return type and type of arg1,
    are not replaced to alias
    """
    return 1

conf.py

from os.path import join, abspath
import sys
sys.path.insert(0, abspath(join(__file__, "../../..")))

extensions = [
    'sphinx.ext.autodoc',
]
autodoc_type_aliases = {
    "Alias.alias": "alias",
}

index.rst

Minimal Reproducible Example
=======================================

.. toctree::
    ./modules
    ./source/index

detail.rst

detail package
==============

Submodules
----------

detail.minimum module
---------------------

.. automodule:: detail.minimum
   :members:
   :undoc-members:
   :show-inheritance:

Module contents
---------------

.. automodule:: detail
   :members:
   :undoc-members:
   :show-inheritance:

Environment Information

Platform:              win32; (Windows-10-10.0.19045-SP0)
Python version:        3.11.8 (tags/v3.11.8:db85d51, Feb  6 2024, 22:03:32) [MSC v.1937 64 bit (AMD64)])
Python implementation: CPython
Sphinx version:        8.1.3
Docutils version:      0.20.1
Jinja2 version:        3.1.4
Pygments version:      2.18.0

Sphinx extensions

["sphinx.ext.autodoc"]

Additional context

generated html

<html lang="en" data-content_root="./"><head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="viewport" content="width=device-width, initial-scale=1">

    <title>detail package — Project name not set  documentation</title>
    <link rel="stylesheet" type="text/css" href="_static/pygments.css?v=d1102ebc">
    <link rel="stylesheet" type="text/css" href="_static/alabaster.css?v=12dfc556">
    <script src="_static/documentation_options.js?v=5929fcd5"></script>
    <script src="_static/doctools.js?v=9bcbadda"></script>
    <script src="_static/sphinx_highlight.js?v=dc90522c"></script>
    <link rel="index" title="Index" href="genindex.html">
    <link rel="search" title="Search" href="search.html">
    <link rel="next" title="sphinx_bug documentation" href="source/index.html">
    <link rel="prev" title="detail" href="modules.html">
   
  <link rel="stylesheet" href="_static/custom.css" type="text/css">
  

  
  

  </head><body>
  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          

          <div class="body" role="main">
            
  <section id="detail-package">
<h1>detail package<a class="headerlink" href="#detail-package" title="Link to this heading"></a></h1>
<section id="submodules">
<h2>Submodules<a class="headerlink" href="#submodules" title="Link to this heading"></a></h2>
</section>
<section id="module-detail.minimum">
<span id="detail-minimum-module"></span><h2>detail.minimum module<a class="headerlink" href="#module-detail.minimum" title="Link to this heading"></a></h2>
<dl class="py class">
<dt class="sig sig-object py" id="detail.minimum.Alias">
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">detail.minimum.</span></span><span class="sig-name descname"><span class="pre">Alias</span></span><a class="headerlink" href="#detail.minimum.Alias" title="Link to this definition"></a></dt>
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">object</span></code></p>
<dl class="py attribute">
<dt class="sig sig-object py" id="detail.minimum.Alias.alias">
<span class="sig-name descname"><span class="pre">alias</span></span><a class="headerlink" href="#detail.minimum.Alias.alias" title="Link to this definition"></a></dt>
<dd><p>alias of <code class="xref py py-class docutils literal notranslate"><span class="pre">int</span></code></p>
</dd></dl>

</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="detail.minimum.func">
<span class="sig-prename descclassname"><span class="pre">detail.minimum.</span></span><span class="sig-name descname"><span class="pre">func</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">arg1</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">alias</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">arg2</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">alias</span></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon"></span> <span class="sig-return-typehint"><span class="pre">alias</span></span></span><a class="headerlink" href="#detail.minimum.func" title="Link to this definition"></a></dt>
<dd><p>expected behavior.
<cite>Alias.alias</cite> is replaced to <cite>alias</cite>.</p>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="detail.minimum.func_buggy">
<span class="sig-prename descclassname"><span class="pre">detail.minimum.</span></span><span class="sig-name descname"><span class="pre">func_buggy</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">arg1</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">Alias.alias</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">arg2</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">Alias.alias</span><span class="w"> </span><span class="p"><span class="pre">|</span></span><span class="w"> </span><span class="pre">str</span></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon"></span> <span class="sig-return-typehint"><span class="pre">Alias.alias</span></span></span><a class="headerlink" href="#detail.minimum.func_buggy" title="Link to this definition"></a></dt>
<dd><p>types,
including return type and type of arg1,
are not replaced to alias</p>
</dd></dl>

</section>
<section id="module-detail">
<span id="module-contents"></span><h2>Module contents<a class="headerlink" href="#module-detail" title="Link to this heading"></a></h2>
</section>
</section>


          </div>
          
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="Main">
        <div class="sphinxsidebarwrapper">
<h1 class="logo"><a href="index.html">Project name not set</a></h1>








<h3>Navigation</h3>
<ul class="current">
<li class="toctree-l1 current"><a class="reference internal" href="modules.html">detail</a><ul class="current">
<li class="toctree-l2 current"><a class="current reference internal" href="#">detail package</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#submodules">Submodules</a></li>
<li class="toctree-l3"><a class="reference internal" href="#module-detail.minimum">detail.minimum module</a><ul>
<li class="toctree-l4"><a class="reference internal" href="#detail.minimum.Alias"><code class="docutils literal notranslate"><span class="pre">Alias</span></code></a><ul>
<li class="toctree-l5"><a class="reference internal" href="#detail.minimum.Alias.alias"><code class="docutils literal notranslate"><span class="pre">Alias.alias</span></code></a></li>
</ul>
</li>
<li class="toctree-l4"><a class="reference internal" href="#detail.minimum.func"><code class="docutils literal notranslate"><span class="pre">func()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#detail.minimum.func_buggy"><code class="docutils literal notranslate"><span class="pre">func_buggy()</span></code></a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="#module-detail">Module contents</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="source/index.html">sphinx_bug documentation</a></li>
</ul>

<div class="relations">
<h3>Related Topics</h3>
<ul>
  <li><a href="index.html">Documentation overview</a><ul>
  <li><a href="modules.html">detail</a><ul>
      <li>Previous: <a href="modules.html" title="previous chapter">detail</a></li>
      <li>Next: <a href="source/index.html" title="next chapter">sphinx_bug documentation</a></li>
  </ul></li>
  </ul></li>
</ul>
</div>
<search id="searchbox" style="display: block;" role="search">
  <h3 id="searchlabel">Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false">
      <input type="submit" value="Go">
    </form>
    </div>
</search>
<script>document.getElementById('searchbox').style.display = "block"</script>








        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="footer">
      ©.
      
      |
      Powered by <a href="https://www.sphinx-doc.org/">Sphinx 8.1.3</a>
      &amp; <a href="https://alabaster.readthedocs.io">Alabaster 0.7.16</a>
      
      |
      <a href="_sources/detail.rst.txt" rel="nofollow">Page source</a>
    </div>

    

    
  
</body></html>
@AA-Turner AA-Turner added extensions:autodoc awaiting:response Waiting for a response from the author of this issue labels Jan 10, 2025
@AA-Turner
Copy link
Member

Hi @ej-toita, please include the main rST file in the bug report, there is currently no ..auto{whatever}:: directive.

A

1 similar comment
@AA-Turner
Copy link
Member

Hi @ej-toita, please include the main rST file in the bug report, there is currently no ..auto{whatever}:: directive.

A

@ej-toita
Copy link
Author

@AA-Turner thanks! I added detail.rst in the description.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting:response Waiting for a response from the author of this issue extensions:autodoc type:bug
Projects
None yet
Development

No branches or pull requests

2 participants