14
14
15
15
A micro report is a tree of layout and content objects.
16
16
"""
17
- from typing import Optional
17
+ from typing import Any , Iterable , Iterator , List , Optional , Union
18
+
19
+ from pylint .reporters .ureports .text_writer import TextWriter
18
20
19
21
20
22
class VNode :
21
- def __init__ (self , nid = None ):
22
- self .id = nid
23
- # navigation
24
- self .parent = None
25
- self .children = []
26
- self .visitor_name = self .__class__ .__name__ .lower ()
27
-
28
- def __iter__ (self ):
23
+ def __init__ (self ) -> None :
24
+ self .parent : Optional ["BaseLayout" ] = None
25
+ self .children : List ["VNode" ] = []
26
+ self .visitor_name : str = self .__class__ .__name__ .lower ()
27
+
28
+ def __iter__ (self ) -> Iterator ["VNode" ]:
29
29
return iter (self .children )
30
30
31
- def accept (self , visitor , * args , ** kwargs ) :
31
+ def accept (self , visitor : TextWriter , * args : Any , ** kwargs : Any ) -> None :
32
32
func = getattr (visitor , f"visit_{ self .visitor_name } " )
33
33
return func (self , * args , ** kwargs )
34
34
@@ -44,8 +44,8 @@ class BaseLayout(VNode):
44
44
* children : components in this table (i.e. the table's cells)
45
45
"""
46
46
47
- def __init__ (self , children = (), ** kwargs ) :
48
- super ().__init__ (** kwargs )
47
+ def __init__ (self , children : Iterable [ Union [ "Text" , str ]] = ()) -> None :
48
+ super ().__init__ ()
49
49
for child in children :
50
50
if isinstance (child , VNode ):
51
51
self .append (child )
@@ -63,14 +63,14 @@ def insert(self, index: int, child: VNode) -> None:
63
63
self .children .insert (index , child )
64
64
child .parent = self
65
65
66
- def parents (self ):
66
+ def parents (self ) -> List [ "BaseLayout" ] :
67
67
"""return the ancestor nodes"""
68
68
assert self .parent is not self
69
69
if self .parent is None :
70
70
return []
71
71
return [self .parent ] + self .parent .parents ()
72
72
73
- def add_text (self , text ) :
73
+ def add_text (self , text : str ) -> None :
74
74
"""shortcut to add text data"""
75
75
self .children .append (Text (text ))
76
76
@@ -85,11 +85,8 @@ class Text(VNode):
85
85
* data : the text value as an encoded or unicode string
86
86
"""
87
87
88
- def __init__ (self , data , escaped = True , ** kwargs ):
89
- super ().__init__ (** kwargs )
90
- # if isinstance(data, unicode):
91
- # data = data.encode('ascii')
92
- assert isinstance (data , str ), data .__class__
88
+ def __init__ (self , data : str , escaped : bool = True ) -> None :
89
+ super ().__init__ ()
93
90
self .escaped = escaped
94
91
self .data = data
95
92
@@ -117,22 +114,28 @@ class Section(BaseLayout):
117
114
as a first paragraph
118
115
"""
119
116
120
- def __init__ (self , title = None , description = None , ** kwargs ):
121
- super ().__init__ (** kwargs )
117
+ def __init__ (
118
+ self ,
119
+ title : Optional [str ] = None ,
120
+ description : Optional [str ] = None ,
121
+ children : Iterable [Union ["Text" , str ]] = (),
122
+ ) -> None :
123
+ super ().__init__ (children = children )
122
124
if description :
123
125
self .insert (0 , Paragraph ([Text (description )]))
124
126
if title :
125
127
self .insert (0 , Title (children = (title ,)))
126
- self .report_id : Optional [ str ] = None
128
+ self .report_id : str = "" # Used in ReportHandlerMixin.make_reports
127
129
128
130
129
131
class EvaluationSection (Section ):
130
- def __init__ (self , message , ** kwargs ):
131
- super ().__init__ (** kwargs )
132
+ def __init__ (
133
+ self , message : str , children : Iterable [Union ["Text" , str ]] = ()
134
+ ) -> None :
135
+ super ().__init__ (children = children )
132
136
title = Paragraph ()
133
137
title .append (Text ("-" * len (message )))
134
138
self .append (title )
135
-
136
139
message_body = Paragraph ()
137
140
message_body .append (Text (message ))
138
141
self .append (message_body )
@@ -169,8 +172,15 @@ class Table(BaseLayout):
169
172
* title : the table's optional title
170
173
"""
171
174
172
- def __init__ (self , cols , title = None , rheaders = 0 , cheaders = 0 , ** kwargs ):
173
- super ().__init__ (** kwargs )
175
+ def __init__ (
176
+ self ,
177
+ cols : int ,
178
+ title : Optional [str ] = None ,
179
+ rheaders : int = 0 ,
180
+ cheaders : int = 0 ,
181
+ children : Iterable [Union ["Text" , str ]] = (),
182
+ ) -> None :
183
+ super ().__init__ (children = children )
174
184
assert isinstance (cols , int )
175
185
self .cols = cols
176
186
self .title = title
0 commit comments