sphinx-autodoc-typehints icon indicating copy to clipboard operation
sphinx-autodoc-typehints copied to clipboard

Find a way to make sphinx output in tests more predictable

Open flying-sheep opened this issue 3 years ago • 3 comments

The Sphinx output changes depending on if PEP 604 Union syntax is used. It’s not about from __future__ import annotations, it’s about actually using the syntax!

Even on versions < 3.10, a simple type like int gets compiled to different things, depending on what syntax is used in the file:

  • "int" if the file contains no new-style union syntax,
  • *int* if the file contains new-style union syntax,

E.g. when you don‘t use | union syntax,

from __future__ import annotations

def function(x: bool) -> str: ...

gets compiled to ":

...
Parameters:
   * **x** ("bool") -- foo

And when you do use | union syntax anywhere in the file (or is it just anywhere in the compilation unit?),

from __future__ import annotations

def function(x: bool) -> str | int: ...

gets compiled to *:

...
Parameters:
   * **x** (*bool*) -- foo

flying-sheep avatar Jan 05 '22 09:01 flying-sheep

A PR for this would we welcome.

gaborbernat avatar Jan 08 '22 11:01 gaborbernat

Idk what the best approach is, or even where to fix this. Can we configure Sphinx to produce more predictable output? Or do we need an upstream change there?

flying-sheep avatar Jan 10 '22 08:01 flying-sheep

That would be to discover :thinking:

gaborbernat avatar Jan 10 '22 08:01 gaborbernat