From 67cc9a9f169eef57f2bd42af06614c32e065412a Mon Sep 17 00:00:00 2001 From: mvdbeek Date: Thu, 1 Feb 2024 10:34:03 +0100 Subject: [PATCH] Fix type annotation for xml_to_string --- lib/galaxy/tool_util/data/__init__.py | 6 ++---- lib/galaxy/util/__init__.py | 9 ++++----- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/lib/galaxy/tool_util/data/__init__.py b/lib/galaxy/tool_util/data/__init__.py index 33c2e7eced12..655597b39f39 100644 --- a/lib/galaxy/tool_util/data/__init__.py +++ b/lib/galaxy/tool_util/data/__init__.py @@ -880,13 +880,11 @@ def to_dict(self, view: str = "collection", value_mapper: Optional[Dict[str, Cal @overload -def _expand_here_template(content: str, here: Optional[str]) -> str: - ... +def _expand_here_template(content: str, here: Optional[str]) -> str: ... @overload -def _expand_here_template(content: None, here: Optional[str]) -> None: - ... +def _expand_here_template(content: None, here: Optional[str]) -> None: ... def _expand_here_template(content: Optional[str], here: Optional[str]) -> Optional[str]: diff --git a/lib/galaxy/util/__init__.py b/lib/galaxy/util/__init__.py index 249d8f293739..6949dbafbb71 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"):