diff --git a/lib/galaxy/util/__init__.py b/lib/galaxy/util/__init__.py index 249d8f293739..86eba2f38089 100644 --- a/lib/galaxy/util/__init__.py +++ b/lib/galaxy/util/__init__.py @@ -391,15 +391,14 @@ def parse_xml_string_to_etree(xml_string: str, strip_whitespace: bool = True) -> return ElementTree(parse_xml_string(xml_string=xml_string, strip_whitespace=strip_whitespace)) -def xml_to_string(elem: Element, pretty: bool = False) -> str: +def xml_to_string(elem: Optional[Element], pretty: bool = False) -> str: """ Returns a string from an xml tree. """ + if elem is None: + return "" try: - if elem is not None: - xml_str = etree.tostring(elem, encoding="unicode") - else: - xml_str = "" + xml_str = etree.tostring(elem, encoding="unicode") except TypeError as e: # we assume this is a comment if hasattr(elem, "text"): @@ -1080,21 +1079,25 @@ def string_as_bool_or_none(string): @overload -def listify(item: Union[None, Literal[False]], do_strip: bool = False) -> List: ... +def listify(item: Union[None, Literal[False]], do_strip: bool = False) -> List: + ... @overload -def listify(item: str, do_strip: bool = False) -> List[str]: ... +def listify(item: str, do_strip: bool = False) -> List[str]: + ... @overload -def listify(item: Union[List[ItemType], Tuple[ItemType, ...]], do_strip: bool = False) -> List[ItemType]: ... +def listify(item: Union[List[ItemType], Tuple[ItemType, ...]], do_strip: bool = False) -> List[ItemType]: + ... # Unfortunately we cannot use ItemType .. -> List[ItemType] in the next overload # because then that would also match Union types. @overload -def listify(item: Any, do_strip: bool = False) -> List: ... +def listify(item: Any, do_strip: bool = False) -> List: + ... def listify(item: Any, do_strip: bool = False) -> List: @@ -1153,7 +1156,8 @@ def unicodify( # type: ignore[misc] error: str = "replace", strip_null: bool = False, log_exception: bool = True, -) -> None: ... +) -> None: + ... @overload @@ -1163,7 +1167,8 @@ def unicodify( error: str = "replace", strip_null: bool = False, log_exception: bool = True, -) -> str: ... +) -> str: + ... def unicodify(