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'>}}
- classmethod register_parser(ast_cls: Type[AstArgumentParser]) Type[AstArgumentParser][source]
Register an AstArgumentParser class for tracking references to an
argparse.ArgumentParseror subclass thereof. May be used as a decorator.- Parameters:
ast_cls¶ –
AstArgumentParseror 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:
objectDecorator 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:
ABCBase 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_funcdecorator.- 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.
- 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.
- groups: list[ArgGroup | MutuallyExclusiveGroup]
- add_mutually_exclusive_group(node: InitNode, tracked_refs: TrackedRefMap) MutuallyExclusiveGroup[source]
- class cli_command_parser.conversion.argparse_ast.ArgGroup(node: InitNode, parent: AstCallable | Script, tracked_refs: TrackedRefMap)[source]
Bases:
ArgCollectionA 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:
ArgGroupA 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:
AstCallableRepresents a subparsers action obtained by calling
parser.add_subparsers(). Contrary to the way the represented class behaves, whenadd_parser()is called, the subparser is stored directly on the parent parser rather than within this instance.- parent: AstArgumentParser
- represents(*, title=None, description=None, prog=None, dest=None, help=None, action=None, option_string=None, required=None, metavar=None)
- 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.
- represents
alias of
ArgumentParser
- 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