44from typing import List
55from typing import Optional
66from typing import Set
7+ from typing import Tuple
78
89
910class Block (abc .ABC ):
@@ -67,7 +68,7 @@ def set_parser_metadata(self, key: str, value: Any):
6768 See attribute ``parser_metadata`` for more information."""
6869 self ._parser_metadata [key ] = value
6970
70- def __eq__ (self , other ) :
71+ def __eq__ (self , other : object ) -> bool :
7172 # make sure they have the same type and same content
7273 return (
7374 isinstance (other , self .__class__ )
@@ -108,10 +109,10 @@ def value(self) -> str:
108109 def value (self , value : str ):
109110 self ._value = value
110111
111- def __str__ (self ):
112+ def __str__ (self ) -> str :
112113 return f"String (line: { self .start_line } , key: `{ self .key } `): `{ self .value } `"
113114
114- def __repr__ (self ):
115+ def __repr__ (self ) -> str :
115116 return (
116117 f"String(key=`{ self .key } `, value=`{ self .value } `, "
117118 f"start_line={ self .start_line } , raw=`{ self .raw } `)"
@@ -134,10 +135,10 @@ def value(self) -> str:
134135 def value (self , value : str ):
135136 self ._value = value
136137
137- def __str__ (self ):
138+ def __str__ (self ) -> str :
138139 return f"Preamble (line: { self .start_line } ): `{ self .value } `"
139140
140- def __repr__ (self ):
141+ def __repr__ (self ) -> str :
141142 return f"Preamble(value=`{ self .value } `, " f"start_line={ self .start_line } , raw=`{ self .raw } `)"
142143
143144
@@ -157,10 +158,10 @@ def comment(self) -> str:
157158 def comment (self , value : str ):
158159 self ._comment = value
159160
160- def __str__ (self ):
161+ def __str__ (self ) -> str :
161162 return f"ExplicitComment (line: { self .start_line } ): `{ self .comment } `"
162163
163- def __repr__ (self ):
164+ def __repr__ (self ) -> str :
164165 return (
165166 f"ExplicitComment(comment=`{ self .comment } `, "
166167 f"start_line={ self .start_line } , raw=`{ self .raw } `)"
@@ -183,10 +184,10 @@ def comment(self) -> str:
183184 def comment (self , value : str ):
184185 self ._comment = value
185186
186- def __str__ (self ):
187+ def __str__ (self ) -> str :
187188 return f"ImplicitComment (line: { self .start_line } ): `{ self .comment } `"
188189
189- def __repr__ (self ):
190+ def __repr__ (self ) -> str :
190191 return (
191192 f"ImplicitComment(comment=`{ self .comment } `, "
192193 f"start_line={ self .start_line } , raw=`{ self .raw } `)"
@@ -224,18 +225,18 @@ def start_line(self) -> int:
224225 """The line number of the first line of this field in the originally parsed string."""
225226 return self ._start_line
226227
227- def __eq__ (self , other ) :
228+ def __eq__ (self , other : object ) -> bool :
228229 # make sure they have the same type and same content
229230 return (
230231 isinstance (other , self .__class__ )
231232 and isinstance (self , other .__class__ )
232233 and self .__dict__ == other .__dict__
233234 )
234235
235- def __str__ (self ):
236+ def __str__ (self ) -> str :
236237 return f"Field (line: { self .start_line } , key: `{ self .key } `): `{ self .value } `"
237238
238- def __repr__ (self ):
239+ def __repr__ (self ) -> str :
239240 return f"Field(key=`{ self .key } `, value=`{ self .value } `, " f"start_line={ self .start_line } )"
240241
241242
@@ -256,7 +257,7 @@ def __init__(
256257 self ._fields = fields
257258
258259 @property
259- def entry_type (self ):
260+ def entry_type (self ) -> str :
260261 """The type of the entry, e.g. ``article`` in ``@article{Cesar2013, ...}``."""
261262 return self ._entry_type
262263
@@ -265,7 +266,7 @@ def entry_type(self, value: str):
265266 self ._entry_type = value
266267
267268 @property
268- def key (self ):
269+ def key (self ) -> str :
269270 """The key of the entry, e.g. ``Cesar2013`` in ``@article{Cesar2013, ...}``."""
270271 return self ._key
271272
@@ -343,15 +344,15 @@ def __setitem__(self, key: str, value: Any):
343344 """
344345 self .set_field (Field (key , value ))
345346
346- def __delitem__ (self , key ) :
347+ def __delitem__ (self , key : str ) -> None :
347348 """Dict-mimicking index.
348349
349350 This serves for partial v1.x backwards compatibility,
350351 as well as for a shorthand for `pop`.
351352 """
352353 self .pop (key )
353354
354- def items (self ):
355+ def items (self ) -> List [ Tuple [ str , Any ]] :
355356 """Dict-mimicking, for partial v1.x backwards compatibility.
356357
357358 For newly written code, it's recommended to use `entry.entry_type`,
@@ -361,12 +362,12 @@ def items(self):
361362 ("ID" , self .key ),
362363 ] + [(f .key , f .value ) for f in self .fields ]
363364
364- def __str__ (self ):
365+ def __str__ (self ) -> str :
365366 lines = [f"Entry (line: { self .start_line } , type: `{ self .entry_type } `, key: `{ self .key } `):" ]
366367 lines .extend ([f"\t `{ f .key } ` = `{ f .value } `" for f in self .fields ])
367368 return "\n " .join (lines )
368369
369- def __repr__ (self ):
370+ def __repr__ (self ) -> str :
370371 return (
371372 f"Entry(entry_type=`{ self .entry_type } `, key=`{ self .key } `, "
372373 f"fields=`{ self .fields .__repr__ ()} `, start_line={ self .start_line } )"
0 commit comments