1
1
import string
2
- from typing import Iterable
2
+ from collections . abc import Set
3
3
4
4
import docutils .nodes as nodes
5
5
@@ -11,25 +11,11 @@ class DescriptionParser(nodes.NodeVisitor):
11
11
12
12
def __init__ (
13
13
self ,
14
+ document : nodes .document ,
15
+ * ,
14
16
desc_len : int ,
15
- known_titles : Iterable [str ] = None ,
16
- document : nodes .document = None ,
17
+ known_titles : Set [str ] = frozenset (),
17
18
):
18
- # Hack to prevent requirement for the doctree to be passed in.
19
- # It's only used by doctree.walk(...) to print debug messages.
20
- if document is None :
21
-
22
- class document_cls :
23
- class reporter :
24
- @staticmethod
25
- def debug (* args , ** kwaargs ):
26
- pass
27
-
28
- document = document_cls ()
29
-
30
- if known_titles == None :
31
- known_titles = []
32
-
33
19
super ().__init__ (document )
34
20
self .description = ""
35
21
self .desc_len = desc_len
@@ -115,9 +101,10 @@ def dispatch_departure(self, node: nodes.Element) -> None:
115
101
def get_description (
116
102
doctree : nodes .document ,
117
103
description_length : int ,
118
- known_titles : Iterable [str ] = None ,
119
- document : nodes .document = None ,
104
+ known_titles : Set [str ] = frozenset (),
120
105
):
121
- mcv = DescriptionParser (description_length , known_titles , document )
106
+ mcv = DescriptionParser (
107
+ doctree , desc_len = description_length , known_titles = known_titles
108
+ )
122
109
doctree .walkabout (mcv )
123
110
return mcv .description
0 commit comments