Skip to content

Commit cea4107

Browse files
committed
Fix ElementTree type annotations for Python 3.9+ compatibility
Use string literal type annotations for ElementTree[Element[str]] to avoid runtime TypeError when importing the module in Python 3.9, while maintaining precise type checking for mypy.
1 parent 48e4d11 commit cea4107

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

planemo/autoupdate.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def bump_version(version_str: str) -> str:
6767
return ".".join(map(str, base_version))
6868

6969

70-
def find_macros(xml_tree: ElementTree[Element[str]]) -> List[Any]:
70+
def find_macros(xml_tree: "ElementTree[Element[str]]") -> List[Any]:
7171
"""
7272
Get macros from the XML tree
7373
"""
@@ -77,7 +77,7 @@ def find_macros(xml_tree: ElementTree[Element[str]]) -> List[Any]:
7777
return macros
7878

7979

80-
def get_requirements(xml_tree: ElementTree[Element[str]]) -> Tuple[Dict[str, Dict[str, Optional[str]]], Optional[str]]:
80+
def get_requirements(xml_tree: "ElementTree[Element[str]]") -> Tuple[Dict[str, Dict[str, Optional[str]]], Optional[str]]:
8181
"""
8282
Get requirements from the XML tree
8383
"""
@@ -95,7 +95,7 @@ def get_requirements(xml_tree: ElementTree[Element[str]]) -> Tuple[Dict[str, Dic
9595
return requirements, main_req
9696

9797

98-
def get_tokens(xml_tree: ElementTree[Element[str]]) -> Dict[str, Dict[str, Optional[str]]]:
98+
def get_tokens(xml_tree: "ElementTree[Element[str]]") -> Dict[str, Dict[str, Optional[str]]]:
9999
"""
100100
Get tokens from the XML tree
101101
"""
@@ -127,7 +127,7 @@ def check_conda(package_name: str, ctx: "PlanemoCliContext", **kwds) -> str:
127127

128128
def update_xml(
129129
tool_path: str,
130-
xml_tree: ElementTree[Element[str]],
130+
xml_tree: "ElementTree[Element[str]]",
131131
tags_to_update: List[Dict[str, str]],
132132
wrapper_version_token: Optional[Union[int, str]],
133133
is_macro: bool = False,
@@ -165,7 +165,7 @@ def update_requirement(xml_text, tag, requirement_value):
165165

166166

167167
def create_requirement_dict(
168-
xml_files: Dict[str, ElementTree[Element[str]]], skip_reqs: List[str]
168+
xml_files: Dict[str, "ElementTree[Element[str]]"], skip_reqs: List[str]
169169
) -> Tuple[Dict[str, Dict[str, Dict[str, Optional[str]]]], Optional[Tuple[str, str]]]:
170170
"""
171171
Create dict with requirements and find main requirement
@@ -185,7 +185,7 @@ def create_requirement_dict(
185185

186186

187187
def create_token_dict(
188-
ctx: "PlanemoCliContext", xml_files: Dict[str, ElementTree[Element[str]]], main_req: Tuple[str, str], **kwds
188+
ctx: "PlanemoCliContext", xml_files: Dict[str, "ElementTree[Element[str]]"], main_req: Tuple[str, str], **kwds
189189
) -> Tuple[
190190
Dict[str, Dict[str, Dict[str, Optional[str]]]], DefaultDict[str, List[Dict[str, str]]], Optional[str], Optional[str]
191191
]:
@@ -211,7 +211,7 @@ def create_token_dict(
211211

212212
def perform_required_update(
213213
ctx: "PlanemoCliContext",
214-
xml_files: Dict[str, ElementTree[Element[str]]],
214+
xml_files: Dict[str, "ElementTree[Element[str]]"],
215215
tool_path: str,
216216
requirements: Dict[str, Dict[str, Dict[str, Optional[str]]]],
217217
tokens: Dict[str, Dict[str, Dict[str, Optional[str]]]],

0 commit comments

Comments
 (0)