1414
1515A micro report is a tree of layout and content objects.
1616"""
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
1820
1921
2022class 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" ]:
2929 return iter (self .children )
3030
31- def accept (self , visitor , * args , ** kwargs ) :
31+ def accept (self , visitor : TextWriter , * args : Any , ** kwargs : Any ) -> None :
3232 func = getattr (visitor , f"visit_{ self .visitor_name } " )
3333 return func (self , * args , ** kwargs )
3434
@@ -44,8 +44,8 @@ class BaseLayout(VNode):
4444 * children : components in this table (i.e. the table's cells)
4545 """
4646
47- def __init__ (self , children = (), ** kwargs ) :
48- super ().__init__ (** kwargs )
47+ def __init__ (self , children : Iterable [ Union [ "Text" , str ]] = ()) -> None :
48+ super ().__init__ ()
4949 for child in children :
5050 if isinstance (child , VNode ):
5151 self .append (child )
@@ -63,14 +63,14 @@ def insert(self, index: int, child: VNode) -> None:
6363 self .children .insert (index , child )
6464 child .parent = self
6565
66- def parents (self ):
66+ def parents (self ) -> List [ "BaseLayout" ] :
6767 """return the ancestor nodes"""
6868 assert self .parent is not self
6969 if self .parent is None :
7070 return []
7171 return [self .parent ] + self .parent .parents ()
7272
73- def add_text (self , text ) :
73+ def add_text (self , text : str ) -> None :
7474 """shortcut to add text data"""
7575 self .children .append (Text (text ))
7676
@@ -85,11 +85,8 @@ class Text(VNode):
8585 * data : the text value as an encoded or unicode string
8686 """
8787
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__ ()
9390 self .escaped = escaped
9491 self .data = data
9592
@@ -117,22 +114,28 @@ class Section(BaseLayout):
117114 as a first paragraph
118115 """
119116
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 )
122124 if description :
123125 self .insert (0 , Paragraph ([Text (description )]))
124126 if title :
125127 self .insert (0 , Title (children = (title ,)))
126- self .report_id : Optional [ str ] = None
128+ self .report_id : str = "" # Used in ReportHandlerMixin.make_reports
127129
128130
129131class 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 )
132136 title = Paragraph ()
133137 title .append (Text ("-" * len (message )))
134138 self .append (title )
135-
136139 message_body = Paragraph ()
137140 message_body .append (Text (message ))
138141 self .append (message_body )
@@ -169,8 +172,15 @@ class Table(BaseLayout):
169172 * title : the table's optional title
170173 """
171174
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 )
174184 assert isinstance (cols , int )
175185 self .cols = cols
176186 self .title = title
0 commit comments