Argparse_Ast Module

class cli_command_parser.conversion.argparse_ast.Script(src_text: str, smart_loop_handling: bool = True, path: PathLike | None = None)[source]

Bases: object

mod_cls_to_ast_cls_map: dict[str, dict[str, Type[AstArgumentParser]]] = {'argparse': {'ArgumentParser': <class 'cli_command_parser.conversion.argparse_ast.AstArgumentParser'>}}
path: Path | None
classmethod register_parser(ast_cls: Type[AstArgumentParser]) Type[AstArgumentParser][source]

Register an AstArgumentParser class for tracking references to an argparse.ArgumentParser or subclass thereof. May be used as a decorator.

Parameters:

ast_clsAstArgumentParser or a subclass thereof

Returns:

The decorated class, unmodified

add_parser(ast_cls: Type[ParserObj], node: InitNode, tracked_refs: TrackedRefMap) ParserObj[source]
property parsers: list[AstArgumentParser][source]
class cli_command_parser.conversion.argparse_ast.visit_func(func)[source]

Bases: object

Decorator for AstCallable methods that can be called by an AST visitor.

func
class cli_command_parser.conversion.argparse_ast.AddVisitedChild(child_cls: Type[AC], attr: str)[source]

Bases: Generic[AC]

Simplifies the definition of an add_child method that can be called by an AST visitor, where possible.

child_cls
list_attr
class cli_command_parser.conversion.argparse_ast.AstCallable(node: InitNode, parent: AstCallable | Script, tracked_refs: TrackedRefMap)[source]

Bases: ABC

Base class for classes that act as stand-ins for real classes, for tracking instances of those classes and methods that were called on those instances while visiting AST nodes.

Methods that should be tracked / should be called while visiting AST nodes must be registered with the visit_func decorator.

represents: ClassVar[Callable]
visit_funcs: set[str] = {}
classmethod __init_subclass__(represents: Callable | None = None, **kwargs)[source]
get_tracked_refs(module: str, name: str, default: D | _NotSetType = _NotSetType._NotSet) set[str] | D[source]

Get the set of variable names that are references to the specified tracked item.

property signature: Signature[source]
property call: Call[source]
property init_func_name: str[source]

The name or alias of the function/callable that was used to initialize this object

property init_func_args: list[str][source]
property init_func_raw_kwargs: dict[str, AST][source]
property init_func_kwargs: dict[str, OptStr][source]
init_call_repr() str[source]
pprint(indent: int = 0)[source]
class cli_command_parser.conversion.argparse_ast.ParserArg(node: InitNode, parent: AstCallable | Script, tracked_refs: TrackedRefMap)[source]

Bases: AstCallable

parent: ArgCollection
represents(*args, **kwargs)

add_argument(dest, …, name=value, …) add_argument(option_string, option_string, …, name=value, …)

class cli_command_parser.conversion.argparse_ast.ArgCollection(node: InitNode, parent: AstCallable | Script, tracked_refs: TrackedRefMap)[source]

Bases: AstCallable, ABC

parent: ArgCollection | Script
add_argument: AddVisitedChild[ParserArg]

Simplifies the definition of an add_child method that can be called by an AST visitor, where possible.

classmethod __init_subclass__(children: Collection[str] = (), **kwargs)[source]
args: list[ParserArg]
groups: list[ArgGroup | MutuallyExclusiveGroup]
add_mutually_exclusive_group(node: InitNode, tracked_refs: TrackedRefMap) MutuallyExclusiveGroup[source]
add_argument_group(node: InitNode, tracked_refs: TrackedRefMap) ArgGroup[source]
grouped_children() Iterator[ACGroup][source]
pprint(indent: int = 0)[source]
visit_funcs: set[str] = {'add_argument', 'add_argument_group', 'add_mutually_exclusive_group'}
class cli_command_parser.conversion.argparse_ast.ArgGroup(node: InitNode, parent: AstCallable | Script, tracked_refs: TrackedRefMap)[source]

Bases: ArgCollection

A group containing zero or more arguments or other argument groups

represents(title=None, description=None, *, prefix_chars=None, argument_default=None, conflict_handler=None)
class cli_command_parser.conversion.argparse_ast.MutuallyExclusiveGroup(node: InitNode, parent: AstCallable | Script, tracked_refs: TrackedRefMap)[source]

Bases: ArgGroup

A mutually exclusive argument group

represents(*, required=False)
class cli_command_parser.conversion.argparse_ast.SubparsersAction(node: InitNode, parent: AstCallable | Script, tracked_refs: TrackedRefMap)[source]

Bases: AstCallable

Represents a subparsers action obtained by calling parser.add_subparsers(). Contrary to the way the represented class behaves, when add_parser() is called, the subparser is stored directly on the parent parser rather than within this instance.

parent: AstArgumentParser
add_parser(node: InitNode, tracked_refs: TrackedRefMap)[source]
represents(*, title=None, description=None, prog=None, dest=None, help=None, action=None, option_string=None, required=None, metavar=None)
visit_funcs: set[str] = {'add_parser'}
class cli_command_parser.conversion.argparse_ast.AstArgumentParser(node: InitNode, parent: Script | ParserObj, tracked_refs: TrackedRefMap)[source]

Bases: ArgCollection

parent: Script | AstArgumentParser
add_subparsers: AddVisitedChild[SubparsersAction]

Simplifies the definition of an add_child method that can be called by an AST visitor, where possible.

sub_parsers: list[SubParser]
represents

alias of ArgumentParser

visit_funcs: set[str] = {'add_argument', 'add_argument_group', 'add_mutually_exclusive_group', 'add_subparsers'}
class cli_command_parser.conversion.argparse_ast.SubParser(node: InitNode, parent: Script | ParserObj, tracked_refs: TrackedRefMap)[source]

Bases: AstArgumentParser

represents(name, *, aliases=(), description=None, prog=None, help=None)
parent: AstArgumentParser | SubParser
sp_parent: SubparsersAction
property init_func_kwargs: dict[str, OptStr][source]