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

Type annotations not hyperlinked with class keyword argument #10954

Open
alexfikl opened this issue Nov 2, 2022 · 0 comments
Open

Type annotations not hyperlinked with class keyword argument #10954

alexfikl opened this issue Nov 2, 2022 · 0 comments

Comments

@alexfikl
Copy link

alexfikl commented Nov 2, 2022

Describe the bug

When rendering the following snippet

def convert_dtype_v1(a: Any, *, dtype: Any = np.int32) -> Any:
    return a.astype(dtype)

the typing annotations are all shown as ~typing.Any and no hyperlinks are generated. The issue seems to be with the np.int32 default argument. As far as I've been able to debug it, it goes through the following steps

  • a string is generated for the signature that contains repr(np.int32).
  • the string is passed to signature_from_str in
    def signature_from_str(signature: str) -> inspect.Signature:
  • ast.parse throws a SyntaxError due to the <class 'numpy.int32'>.
  • handle_signature proceeds to skip the parsing at
    except SyntaxError:

Ideally the type annotations would be rendered and hyperlinked correctly.

How to Reproduce

sphinx-bug-mre.tar.gz contains a minimal example that can be built with the usual

$ sphinx-build -M html . _build
$ # open _build/html/index and see bla bla

On my machine, this results in the rendering below. v0 is rendered as expected, while v1 has all the types as plaintext.

Screenshot_20221102_215027

Environment Information

Platform:              linux; (Linux-6.0.6-arch1-1-x86_64-with-glibc2.36) 
Python version:        3.10.8 (main, Oct 13 2022, 21:13:48) [GCC 12.2.0]) 
Python implementation: CPython 
Sphinx version:        5.3.0 
Docutils version:      0.19 
Jinja2 version:        3.1.2

Sphinx extensions

sphinx.ext.autodoc; sphinx.ext.intersphinx

Additional context

No response

@AA-Turner AA-Turner added this to the some future version milestone Apr 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants