summaryrefslogtreecommitdiff
path: root/sphinx/directives/code.py
diff options
context:
space:
mode:
Diffstat (limited to 'sphinx/directives/code.py')
-rw-r--r--sphinx/directives/code.py29
1 files changed, 8 insertions, 21 deletions
diff --git a/sphinx/directives/code.py b/sphinx/directives/code.py
index e01b8f9ec..12ab51c58 100644
--- a/sphinx/directives/code.py
+++ b/sphinx/directives/code.py
@@ -8,9 +8,8 @@
import sys
import textwrap
-import warnings
from difflib import unified_diff
-from typing import Any, Dict, List, Tuple
+from typing import TYPE_CHECKING, Any, Dict, List, Tuple
from docutils import nodes
from docutils.nodes import Element, Node
@@ -19,14 +18,13 @@ from docutils.statemachine import StringList
from sphinx import addnodes
from sphinx.config import Config
-from sphinx.deprecation import RemovedInSphinx40Warning
from sphinx.directives import optional_int
from sphinx.locale import __
from sphinx.util import logging, parselinenos
from sphinx.util.docutils import SphinxDirective
+from sphinx.util.typing import OptionSpec
-if False:
- # For type annotation
+if TYPE_CHECKING:
from sphinx.application import Sphinx
logger = logging.getLogger(__name__)
@@ -42,7 +40,7 @@ class Highlight(SphinxDirective):
required_arguments = 1
optional_arguments = 0
final_argument_whitespace = False
- option_spec = {
+ option_spec: OptionSpec = {
'force': directives.flag,
'linenothreshold': directives.positive_int,
}
@@ -58,16 +56,6 @@ class Highlight(SphinxDirective):
linenothreshold=linenothreshold)]
-class HighlightLang(Highlight):
- """highlightlang directive (deprecated)"""
-
- def run(self) -> List[Node]:
- warnings.warn('highlightlang directive is deprecated. '
- 'Please use highlight directive instead.',
- RemovedInSphinx40Warning, stacklevel=2)
- return super().run()
-
-
def dedent_lines(lines: List[str], dedent: int, location: Tuple[str, int] = None) -> List[str]:
if not dedent:
return textwrap.dedent(''.join(lines)).splitlines(True)
@@ -116,7 +104,7 @@ class CodeBlock(SphinxDirective):
required_arguments = 0
optional_arguments = 1
final_argument_whitespace = False
- option_spec = {
+ option_spec: OptionSpec = {
'force': directives.flag,
'linenos': directives.flag,
'dedent': optional_int,
@@ -154,7 +142,7 @@ class CodeBlock(SphinxDirective):
lines = dedent_lines(lines, self.options['dedent'], location=location)
code = '\n'.join(lines)
- literal = nodes.literal_block(code, code) # type: Element
+ literal: Element = nodes.literal_block(code, code)
if 'linenos' in self.options or 'lineno-start' in self.options:
literal['linenos'] = True
literal['classes'] += self.options.get('class', [])
@@ -392,7 +380,7 @@ class LiteralInclude(SphinxDirective):
required_arguments = 1
optional_arguments = 0
final_argument_whitespace = True
- option_spec = {
+ option_spec: OptionSpec = {
'dedent': optional_int,
'linenos': directives.flag,
'lineno-start': int,
@@ -434,7 +422,7 @@ class LiteralInclude(SphinxDirective):
reader = LiteralIncludeReader(filename, self.options, self.config)
text, lines = reader.read(location=location)
- retnode = nodes.literal_block(text, text, source=filename) # type: Element
+ retnode: Element = nodes.literal_block(text, text, source=filename)
retnode['force'] = 'force' in self.options
self.set_source_info(retnode)
if self.options.get('diff'): # if diff is set, set udiff
@@ -470,7 +458,6 @@ class LiteralInclude(SphinxDirective):
def setup(app: "Sphinx") -> Dict[str, Any]:
directives.register_directive('highlight', Highlight)
- directives.register_directive('highlightlang', HighlightLang)
directives.register_directive('code-block', CodeBlock)
directives.register_directive('sourcecode', CodeBlock)
directives.register_directive('literalinclude', LiteralInclude)