@@ -216,7 +216,7 @@ def unsafe_string(s: str, isattr: bool = True) -> str:
216216 tree = ast .parse ("'" + s + "'" , mode = 'eval' )
217217 if not isinstance (tree .body , ast .Constant ):
218218 raise ValueError (f"Invalid string '{ s } ' passed to unsafe_string()" )
219- return tree .body .s
219+ return tree .body .value # type: ignore[return-value]
220220
221221 return s
222222
@@ -247,10 +247,12 @@ def xmldump(filehandle: io.TextIOWrapper|None, py_obj: object,
247247 """Create the XML representation as a string."""
248248
249249 fh : io .TextIOWrapper
250+ sio : io .StringIO | None
250251 if filehandle is None :
251- fh = sio = io .StringIO ()
252+ fh = sio = io .StringIO () # type: ignore[assignment]
252253 else :
253254 fh = filehandle
255+ sio = None
254256
255257 omit = omit or ()
256258
@@ -301,7 +303,7 @@ def xmldump(filehandle: io.TextIOWrapper|None, py_obj: object,
301303
302304 fh .write ('</PyObject>\n ' )
303305
304- if filehandle is None :
306+ if sio is not None :
305307 sio .flush ()
306308 return sio .getvalue ()
307309 return None
@@ -454,7 +456,7 @@ def _tag_completer(start_tag: str, orig_thing, close_tag: str, level: int) -> st
454456def _thing_from_dom (dom_node : minidom .Element | minidom .Document , container : Any = None ) -> Any :
455457 """Converts an [xml_pickle] DOM tree to a 'native' Python object"""
456458 node : minidom .Element
457- for node in dom_node .childNodes :
459+ for node in dom_node .childNodes : # type: ignore[assignment]
458460 if not hasattr (node , '_attrs' ) or not node .nodeName != '#text' :
459461 continue
460462
@@ -511,15 +513,15 @@ def _thing_from_dom(dom_node: minidom.Element|minidom.Document, container: Any =
511513 # a value= attribute. ie. pickler can place it in either
512514 # place (based on user preference) and unpickler doesn't care
513515 node_valuetext = ""
514- if 'value' in node ._attrs :
516+ if 'value' in node ._attrs : # type: ignore[attr-defined]
515517 # text in tag
516518 ttext = node .getAttribute ('value' )
517519 node_valuetext = unsafe_string (ttext , isattr = True )
518520 else :
519521 # text in body
520522 node .normalize ()
521523 if node .childNodes :
522- node_valuetext = unsafe_string (node .childNodes [0 ].nodeValue , isattr = False )
524+ node_valuetext = unsafe_string (node .childNodes [0 ].nodeValue , isattr = False ) # type: ignore[arg-type]
523525
524526 # step 1 - set node_val to basic thing
525527 node_val : Any
0 commit comments