Skip to content

Commit

Permalink
Fix typing in postprocess_schema.py
Browse files Browse the repository at this point in the history
  • Loading branch information
mvdbeek committed Dec 6, 2023
1 parent 8a69b37 commit 76ccbd0
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions lib/galaxy/tool_util/schemas/postprocess_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def modify_tree(tree: ast.Module):
for node in ast.walk(tree):
if isinstance(node, ast.ClassDef):
for field in node.body:
if isinstance(field, ast.AnnAssign):
if isinstance(field, ast.AnnAssign) and field.value and hasattr(field.value, "keywords"):
# Replace the "doc" key in the metadata for each field with "description"
for keyword in field.value.keywords:
if keyword.arg == "metadata":
Expand All @@ -63,9 +63,13 @@ def modify_tree(tree: ast.Module):
target_ids = MODIFICATION_BY_MODULE[node.name]
new_body = []
for field in node.body:
if isinstance(field, ast.AnnAssign) and field.target.id in target_ids:
if (
isinstance(field, ast.AnnAssign)
and hasattr(field.target, "id")
and field.target.id in target_ids
):
modification = target_ids[field.target.id]
if modification == "to_union":
if modification == "to_union" and hasattr(field.annotation, "slice"):
original_slice = field.annotation.slice
list_type = ast.Subscript(
value=ast.Name(id="List", ctx=ast.Load()),
Expand All @@ -82,10 +86,11 @@ def modify_tree(tree: ast.Module):
),
ctx=ast.Load(),
)
for keyword in field.value.keywords:
if keyword.arg == "default_factory":
keyword.arg = "default"
keyword.value = ast.NameConstant(value=None)
if field.value and hasattr(field.value, "keywords"):
for keyword in field.value.keywords:
if keyword.arg == "default_factory":
keyword.arg = "default"
keyword.value = ast.NameConstant(value=None)
elif modification == "delete":
continue
new_body.append(field)
Expand Down

0 comments on commit 76ccbd0

Please sign in to comment.