Skip to content

Commit a9dcc72

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 a9dcc72

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

planemo/autoupdate.py

Lines changed: 9 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,9 @@ 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(
81+
xml_tree: "ElementTree[Element[str]]",
82+
) -> Tuple[Dict[str, Dict[str, Optional[str]]], Optional[str]]:
8183
"""
8284
Get requirements from the XML tree
8385
"""
@@ -95,7 +97,7 @@ def get_requirements(xml_tree: ElementTree[Element[str]]) -> Tuple[Dict[str, Dic
9597
return requirements, main_req
9698

9799

98-
def get_tokens(xml_tree: ElementTree[Element[str]]) -> Dict[str, Dict[str, Optional[str]]]:
100+
def get_tokens(xml_tree: "ElementTree[Element[str]]") -> Dict[str, Dict[str, Optional[str]]]:
99101
"""
100102
Get tokens from the XML tree
101103
"""
@@ -127,7 +129,7 @@ def check_conda(package_name: str, ctx: "PlanemoCliContext", **kwds) -> str:
127129

128130
def update_xml(
129131
tool_path: str,
130-
xml_tree: ElementTree[Element[str]],
132+
xml_tree: "ElementTree[Element[str]]",
131133
tags_to_update: List[Dict[str, str]],
132134
wrapper_version_token: Optional[Union[int, str]],
133135
is_macro: bool = False,
@@ -165,7 +167,7 @@ def update_requirement(xml_text, tag, requirement_value):
165167

166168

167169
def create_requirement_dict(
168-
xml_files: Dict[str, ElementTree[Element[str]]], skip_reqs: List[str]
170+
xml_files: Dict[str, "ElementTree[Element[str]]"], skip_reqs: List[str]
169171
) -> Tuple[Dict[str, Dict[str, Dict[str, Optional[str]]]], Optional[Tuple[str, str]]]:
170172
"""
171173
Create dict with requirements and find main requirement
@@ -185,7 +187,7 @@ def create_requirement_dict(
185187

186188

187189
def create_token_dict(
188-
ctx: "PlanemoCliContext", xml_files: Dict[str, ElementTree[Element[str]]], main_req: Tuple[str, str], **kwds
190+
ctx: "PlanemoCliContext", xml_files: Dict[str, "ElementTree[Element[str]]"], main_req: Tuple[str, str], **kwds
189191
) -> Tuple[
190192
Dict[str, Dict[str, Dict[str, Optional[str]]]], DefaultDict[str, List[Dict[str, str]]], Optional[str], Optional[str]
191193
]:
@@ -211,7 +213,7 @@ def create_token_dict(
211213

212214
def perform_required_update(
213215
ctx: "PlanemoCliContext",
214-
xml_files: Dict[str, ElementTree[Element[str]]],
216+
xml_files: Dict[str, "ElementTree[Element[str]]"],
215217
tool_path: str,
216218
requirements: Dict[str, Dict[str, Dict[str, Optional[str]]]],
217219
tokens: Dict[str, Dict[str, Dict[str, Optional[str]]]],

0 commit comments

Comments
 (0)