doc: workaround for ugly API docs for overloaded functions with new Sphinx

New Sphinx added support for overloads and always displays them all with
full type annotations etc. This regresses the API reference for
overloaded functions like `fixture()`, `warns()`, `raises()` and friends
to become impossible to read.

I tried various workarounds but none worked except this one.
This commit is contained in:
Ran Benita
2022-08-13 21:04:59 +03:00
parent 7431750bb6
commit beae7fd0ba
5 changed files with 26 additions and 15 deletions

View File

@@ -12,7 +12,6 @@ from typing import Generic
from typing import List
from typing import Mapping
from typing import Optional
from typing import overload
from typing import Pattern
from typing import Sequence
from typing import Tuple
@@ -28,6 +27,7 @@ if TYPE_CHECKING:
import _pytest._code
from _pytest.compat import final
from _pytest.compat import STRING_TYPES
from _pytest.compat import overload
from _pytest.outcomes import fail
@@ -786,7 +786,7 @@ def raises(
@overload
def raises(
def raises( # noqa: F811
expected_exception: Union[Type[E], Tuple[Type[E], ...]],
func: Callable[..., Any],
*args: Any,
@@ -795,7 +795,7 @@ def raises(
...
def raises(
def raises( # noqa: F811
expected_exception: Union[Type[E], Tuple[Type[E], ...]], *args: Any, **kwargs: Any
) -> Union["RaisesContext[E]", _pytest._code.ExceptionInfo[E]]:
r"""Assert that a code block/function call raises an exception.