Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix up autopygen type annotation #1474

Merged
merged 1 commit into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions planemo/autopygen/source_file_parsing/local_module_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def __init__(self, unknown: Set[str]):

# currently able to resolve add_argument calls containing unknown names,
# and list comprehension assignment
def _reach_top(self, node: ast.Name) -> Tuple[ast.Call, ast.AST]:
def _reach_top(self, node: ast.Name) -> Tuple[ast.Call, ast.Name]:
current = node
parent = current.parent # type: ignore

Expand Down Expand Up @@ -99,14 +99,14 @@ def visit_Name(self, node: ast.Name) -> Any:
)


def handle_local_module_names(actions: List[ast.AST], unknown_names: Set[str]) -> ast.Module:
def handle_local_module_names(actions: List[ast.stmt], unknown_names: Set[str]) -> ast.Module:
"""
Function used to remove assignments and list comprehensions which can't be
resolved

Parameters
----------
actions: List[ast.AST]
actions: List[ast.stmt]
list of actions extracted so far
unknown_names:
set of unknown names that have to be extracted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class ImportDiscovery(Discovery):
Class responsible for discovery and extraction of import statements
"""

def __init__(self, actions: List[ast.AST]):
def __init__(self, actions: List[ast.stmt]):
super(ImportDiscovery, self).__init__(actions)
self.argparse_module_alias: Optional[str] = None
self.argument_parser_alias: Optional[str] = None
Expand Down Expand Up @@ -80,7 +80,7 @@ def visit_ImportFrom(self, node: ast.ImportFrom) -> Any:
if name == ARGPARSE_MODULE_NAME and item.name == ARGUMENT_PARSER_CLASS_NAME:
self.argument_parser_alias = alias

def report_findings(self) -> Tuple[List[ast.AST], Optional[str], Optional[str], Set[str]]:
def report_findings(self) -> Tuple[List[ast.stmt], Optional[str], Optional[str], Set[str]]:
if self.argparse_module_alias is None and self.argument_parser_alias is None:
raise ArgParseImportNotFound("No argparse import found")

Expand All @@ -95,7 +95,7 @@ class SimpleParserDiscoveryAndReplacement(Discovery):
"""

def __init__(
self, actions: List[ast.AST], argparse_alias: str, argument_parser_alias: str, custom_parser_def: ast.ClassDef
self, actions: List[ast.stmt], argparse_alias: str, argument_parser_alias: str, custom_parser_def: ast.ClassDef
):
self.argument_parser_alias = argument_parser_alias
self.argparse_module_alias = argparse_alias
Expand Down Expand Up @@ -179,7 +179,7 @@ class GroupAndSubparsersDiscovery(Discovery):
groups and subparsers
"""

def __init__(self, actions: List[ast.AST], known_names: Set[str], main_name: str):
def __init__(self, actions: List[ast.stmt], known_names: Set[str], main_name: str):
self.main_name = main_name
self.known_names = known_names
super(GroupAndSubparsersDiscovery, self).__init__(actions)
Expand All @@ -205,7 +205,7 @@ class ArgumentCreationDiscovery(Discovery):
and on the argument groups extracted by GroupDiscovery
"""

def __init__(self, actions: List[ast.AST], main_name: str):
def __init__(self, actions: List[ast.stmt], main_name: str):
self.main_name = main_name
super(ArgumentCreationDiscovery, self).__init__(actions)

Expand All @@ -219,11 +219,11 @@ def visit_Call(self, node: ast.Call) -> Any:

self.generic_visit(node)

def report_findings(self) -> Tuple[List[ast.AST]]:
def report_findings(self) -> Tuple[List[ast.stmt]]:
return (self.actions,)


def get_parser_init_and_actions(source: ast.Module) -> Tuple[List[ast.AST], str, Set[str]]:
def get_parser_init_and_actions(source: ast.Module) -> Tuple[List[ast.stmt], str, Set[str]]:
"""
Function used to extract necessary imports, parser and argument creation
function calls
Expand All @@ -239,7 +239,7 @@ def get_parser_init_and_actions(source: ast.Module) -> Tuple[List[ast.AST], str,
section names
"""

actions: List[ast.AST] = []
actions: List[ast.stmt] = []
custom_parser_class_def = obtain_class_def()

if custom_parser_class_def is None:
Expand Down
6 changes: 3 additions & 3 deletions planemo/autopygen/source_file_parsing/parsing_commons.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
)


class CustomAST(ast.AST):
class CustomAST(ast.stmt):
def __init__(self, *args: Any, **kwargs: Any):
super().__init__(*args, **kwargs)
self.parent = None
Expand All @@ -22,13 +22,13 @@ class CustomVisitor(ast.NodeVisitor, abc.ABC):
def report_findings(self) -> Tuple:
pass

def visit_and_report(self, source: ast.AST):
def visit_and_report(self, source: ast.Module):
self.visit(source)
return self.report_findings()


class Discovery(CustomVisitor, abc.ABC):
def __init__(self, actions: List[ast.AST]):
def __init__(self, actions: List[ast.stmt]):
self.actions = actions


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def report_findings(self) -> Tuple:
return self.variable_definitions, self.class_definitions, self.new_known_names


def _insert_into_actions(actions: List[ast.AST], assignments: List[ast.Assign], class_defs: List[ast.ClassDef]):
def _insert_into_actions(actions: List[ast.stmt], assignments: List[ast.Assign], class_defs: List[ast.ClassDef]):
def find_end_of_imports():
index = 0
for item in actions:
Expand Down Expand Up @@ -111,8 +111,8 @@ def find_end_of_assignments(start: int):


def initialize_variables_in_module(
original_module: ast.Module, parser_name: str, actions: List[ast.AST], imported_names: Set[str]
) -> Tuple[List[ast.AST], Set[str]]:
original_module: ast.Module, parser_name: str, actions: List[ast.stmt], imported_names: Set[str]
) -> Tuple[List[ast.stmt], Set[str]]:
"""
Function used to initialize variables that have constant values

Expand All @@ -123,7 +123,7 @@ def initialize_variables_in_module(
AST of the original source file
parser_name : str
default name of the parser
actions : List[ast.AST]
actions : List[ast.stmt]
list of actions extracted so far
imported_names : Set[str]
list of names imported from modules
Expand Down