5
5
import re
6
6
import sys
7
7
from textwrap import dedent
8
- from typing import Iterable , List , Optional
8
+ from typing import Iterable , Iterator , List , Optional
9
9
10
10
from docutils import nodes , statemachine
11
11
from docutils .parsers import rst
20
20
class PipNewsInclude (rst .Directive ):
21
21
required_arguments = 1
22
22
23
- def _is_version_section_title_underline (self , prev , curr ):
23
+ def _is_version_section_title_underline (
24
+ self , prev : Optional [str ], curr : str
25
+ ) -> bool :
24
26
"""Find a ==== line that marks the version section title."""
25
27
if prev is None :
26
28
return False
@@ -30,7 +32,7 @@ def _is_version_section_title_underline(self, prev, curr):
30
32
return False
31
33
return True
32
34
33
- def _iter_lines_with_refs (self , lines ) :
35
+ def _iter_lines_with_refs (self , lines : Iterable [ str ]) -> Iterator [ str ] :
34
36
"""Transform the input lines to add a ref before each section title.
35
37
36
38
This is done by looking one line ahead and locate a title's underline,
@@ -44,6 +46,7 @@ def _iter_lines_with_refs(self, lines):
44
46
for line in lines :
45
47
# Transform the previous line to include an explicit ref.
46
48
if self ._is_version_section_title_underline (prev , line ):
49
+ assert prev is not None
47
50
vref = prev .split (None , 1 )[0 ].replace ("." , "-" )
48
51
yield f".. _`v{ vref } `:"
49
52
yield "" # Empty line between ref and the title.
@@ -53,7 +56,7 @@ def _iter_lines_with_refs(self, lines):
53
56
if prev is not None :
54
57
yield prev
55
58
56
- def run (self ):
59
+ def run (self ) -> List [ nodes . Node ] :
57
60
source = self .state_machine .input_lines .source (
58
61
self .lineno - self .state_machine .input_offset - 1 ,
59
62
)
0 commit comments