Don't filter `ImportWarning in ext.autodoc.importer` (#11024)

This commit is contained in:
Téo Bouvard 2023-07-28 18:53:49 +02:00 committed by GitHub
parent eb3fffc3e9
commit 05a14ff007
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -5,7 +5,6 @@ from __future__ import annotations
import importlib import importlib
import traceback import traceback
import typing import typing
import warnings
from typing import TYPE_CHECKING, Any, Callable, NamedTuple from typing import TYPE_CHECKING, Any, Callable, NamedTuple
from sphinx.ext.autodoc.mock import ismock, undecorate from sphinx.ext.autodoc.mock import ismock, undecorate
@ -61,10 +60,8 @@ def import_module(modname: str, warningiserror: bool = False) -> Any:
Call importlib.import_module(modname), convert exceptions to ImportError Call importlib.import_module(modname), convert exceptions to ImportError
""" """
try: try:
with warnings.catch_warnings(): with logging.skip_warningiserror(not warningiserror):
warnings.filterwarnings("ignore", category=ImportWarning) return importlib.import_module(modname)
with logging.skip_warningiserror(not warningiserror):
return importlib.import_module(modname)
except BaseException as exc: except BaseException as exc:
# Importing modules may cause any side effects, including # Importing modules may cause any side effects, including
# SystemExit, so we need to catch all errors. # SystemExit, so we need to catch all errors.