summaryrefslogtreecommitdiff
path: root/sphinx/util/typing.py
diff options
context:
space:
mode:
authorAdam Turner <9087854+AA-Turner@users.noreply.github.com>2023-01-08 00:27:19 +0000
committerGitHub <noreply@github.com>2023-01-08 00:27:19 +0000
commit67291f414e1b259d6b65bc66ea2874c7131e09bf (patch)
tree40b023c4978f4d04df9ba1852bb1a8f0d865643b /sphinx/util/typing.py
parentf022db3e8ab195e21ce899283f9c9a4e3b99da6b (diff)
downloadsphinx-git-67291f414e1b259d6b65bc66ea2874c7131e09bf.tar.gz
Replace deprecation tooling with module level ``__getattr__`` (#11054)
Diffstat (limited to 'sphinx/util/typing.py')
-rw-r--r--sphinx/util/typing.py25
1 files changed, 15 insertions, 10 deletions
diff --git a/sphinx/util/typing.py b/sphinx/util/typing.py
index 282230e0c..cb571e420 100644
--- a/sphinx/util/typing.py
+++ b/sphinx/util/typing.py
@@ -11,8 +11,6 @@ from typing import Any, Callable, Dict, ForwardRef, List, Tuple, TypeVar, Union
from docutils import nodes
from docutils.parsers.rst.states import Inliner
-from sphinx.deprecation import RemovedInSphinx80Warning, deprecated_alias
-
try:
from types import UnionType # type: ignore # python 3.10 or above
except ImportError:
@@ -342,11 +340,18 @@ def stringify_annotation(
return module_prefix + qualname
-deprecated_alias(__name__,
- {
- 'stringify': stringify_annotation,
- },
- RemovedInSphinx80Warning,
- {
- 'stringify': 'sphinx.util.typing.stringify_annotation',
- })
+# deprecated name -> (object to return, canonical path or empty string)
+_DEPRECATED_OBJECTS = {
+ 'stringify': (stringify_annotation, 'sphinx.util.typing.stringify_annotation'),
+}
+
+
+def __getattr__(name):
+ if name not in _DEPRECATED_OBJECTS:
+ raise AttributeError(f'module {__name__!r} has no attribute {name!r}')
+
+ from sphinx.deprecation import _deprecation_warning
+
+ deprecated_object, canonical_name = _DEPRECATED_OBJECTS[name]
+ _deprecation_warning(__name__, name, canonical_name, remove=(8, 0))
+ return deprecated_object