pyTooling.Attributes.ArgParse.KeyValueFlag

Classes


Classes

class pyTooling.Attributes.ArgParse.KeyValueFlag.NamedKeyValuePairsArgument[source]

Defines a switch argument like --help.

Some of the named parameters passed to add_argument() are predefined (or overwritten) to create a boolean parameter passed to the registered handler method. The boolean parameter is True if the switch argument is present in the commandline arguments, otherwise False.

Inheritance

Inheritance diagram of NamedKeyValuePairsArgument

__init__(short=None, long=None, dest=None, help=None)[source]

The constructor expects positional (*args), the destination parameter name dest and/or named parameters (**kwargs) which are passed to add_argument().

To implement a switch argument, the following named parameters are predefined:

  • action="store_const"

  • const=True

  • default=False

This implements a boolean parameter passed to the handler method.

Parameters:
  • short (str | None)

  • long (str | None)

  • dest (str | None)

  • help (str | None)

property Args: Tuple

A tuple of additional positional parameters (*args) passed to the attribute. These additional parameters are passed without modification to ArgumentParser.

classmethod GetAttributes(method, includeSubClasses=True)

Returns attached attributes of this kind for a given method.

Parameters:
Return type:

Tuple[Attribute, ...]

Returns:

Raises:

TypeError

classmethod GetClasses(scope=None, subclassOf=None)

Return a generator for all classes, where this attribute is attached to.

The resulting item stream can be filtered by:
  • scope - when the item is a nested class in scope scope.

  • subclassOf - when the item is a subclass of subclassOf.

Parameters:
Return type:

Generator[TypeVar(TAttr, bound= Attribute), None, None]

Returns:

A sequence of classes where this attribute is attached to.

classmethod GetFunctions(scope=None)

Return a generator for all functions, where this attribute is attached to.

The resulting item stream can be filtered by:
  • scope - when the item is a nested class in scope scope.

Parameters:

scope (Optional[Type]) – Undocumented.

Return type:

Generator[TypeVar(TAttr, bound= Attribute), None, None]

Returns:

A sequence of functions where this attribute is attached to.

classmethod GetMethods(scope=None)

Return a generator for all methods, where this attribute is attached to.

The resulting item stream can be filtered by:
  • scope - when the item is a nested class in scope scope.

Parameters:

scope (Optional[Type]) – Undocumented.

Return type:

Generator[TypeVar(TAttr, bound= Attribute), None, None]

Returns:

A sequence of methods where this attribute is attached to.

property Handler: Callable

Returns the handler method.

property KWArgs: Dict

A dictionary of additional named parameters (**kwargs) passed to the attribute. These additional parameters are passed without modification to ArgumentParser.

static _AppendAttribute(entity, attribute)

Append an attribute to a language entity (class, method, function).

Hint

This method can be used in attribute groups to apply multiple attributes within __call__ method.

class GroupAttribute(Attribute):
  def __call__(self, entity: Entity) -> Entity:
    self._AppendAttribute(entity, SimpleAttribute(...))
    self._AppendAttribute(entity, SimpleAttribute(...))

    return entity
Parameters:
Raises:

TypeError – If parameter ‘entity’ is not a class, method or function.

Return type:

None

__call__(entity)

Attributes get attached to an entity (function, class, method) and an index is updated at the attribute for reverse lookups.

Parameters:

entity (TypeVar(Entity, bound= Union[Type, Callable])) – Entity (function, class, method), to attach an attribute to.

Return type:

TypeVar(Entity, bound= Union[Type, Callable])

Returns:

Same entity, with attached attribute.

Raises:

TypeError – If parameter ‘entity’ is not a function, class nor method.

_classes: ClassVar[List[Any]] = []

List of classes, this Attribute was attached to.

_functions: ClassVar[List[Any]] = []

List of functions, this Attribute was attached to.

_methods: ClassVar[List[Any]] = []

List of methods, this Attribute was attached to.

_scope: ClassVar[AttributeScope] = 7

Allowed language construct this attribute can be used with.

_handler: Callable

Reference to a method that is called to handle e.g. a sub-command.

class pyTooling.Attributes.ArgParse.KeyValueFlag.ShortKeyValueFlag[source]

Inheritance

Inheritance diagram of ShortKeyValueFlag

__init__(short=None, dest=None, help=None)[source]

The constructor expects positional (*args), the destination parameter name dest and/or named parameters (**kwargs) which are passed to add_argument().

To implement a switch argument, the following named parameters are predefined:

  • action="store_const"

  • const=True

  • default=False

This implements a boolean parameter passed to the handler method.

Parameters:
  • short (str | None)

  • dest (str | None)

  • help (str | None)

property Args: Tuple

A tuple of additional positional parameters (*args) passed to the attribute. These additional parameters are passed without modification to ArgumentParser.

classmethod GetAttributes(method, includeSubClasses=True)

Returns attached attributes of this kind for a given method.

Parameters:
Return type:

Tuple[Attribute, ...]

Returns:

Raises:

TypeError

classmethod GetClasses(scope=None, subclassOf=None)

Return a generator for all classes, where this attribute is attached to.

The resulting item stream can be filtered by:
  • scope - when the item is a nested class in scope scope.

  • subclassOf - when the item is a subclass of subclassOf.

Parameters:
Return type:

Generator[TypeVar(TAttr, bound= Attribute), None, None]

Returns:

A sequence of classes where this attribute is attached to.

classmethod GetFunctions(scope=None)

Return a generator for all functions, where this attribute is attached to.

The resulting item stream can be filtered by:
  • scope - when the item is a nested class in scope scope.

Parameters:

scope (Optional[Type]) – Undocumented.

Return type:

Generator[TypeVar(TAttr, bound= Attribute), None, None]

Returns:

A sequence of functions where this attribute is attached to.

classmethod GetMethods(scope=None)

Return a generator for all methods, where this attribute is attached to.

The resulting item stream can be filtered by:
  • scope - when the item is a nested class in scope scope.

Parameters:

scope (Optional[Type]) – Undocumented.

Return type:

Generator[TypeVar(TAttr, bound= Attribute), None, None]

Returns:

A sequence of methods where this attribute is attached to.

property Handler: Callable

Returns the handler method.

property KWArgs: Dict

A dictionary of additional named parameters (**kwargs) passed to the attribute. These additional parameters are passed without modification to ArgumentParser.

static _AppendAttribute(entity, attribute)

Append an attribute to a language entity (class, method, function).

Hint

This method can be used in attribute groups to apply multiple attributes within __call__ method.

class GroupAttribute(Attribute):
  def __call__(self, entity: Entity) -> Entity:
    self._AppendAttribute(entity, SimpleAttribute(...))
    self._AppendAttribute(entity, SimpleAttribute(...))

    return entity
Parameters:
Raises:

TypeError – If parameter ‘entity’ is not a class, method or function.

Return type:

None

__call__(entity)

Attributes get attached to an entity (function, class, method) and an index is updated at the attribute for reverse lookups.

Parameters:

entity (TypeVar(Entity, bound= Union[Type, Callable])) – Entity (function, class, method), to attach an attribute to.

Return type:

TypeVar(Entity, bound= Union[Type, Callable])

Returns:

Same entity, with attached attribute.

Raises:

TypeError – If parameter ‘entity’ is not a function, class nor method.

_classes: ClassVar[List[Any]] = []

List of classes, this Attribute was attached to.

_functions: ClassVar[List[Any]] = []

List of functions, this Attribute was attached to.

_methods: ClassVar[List[Any]] = []

List of methods, this Attribute was attached to.

_scope: ClassVar[AttributeScope] = 7

Allowed language construct this attribute can be used with.

_handler: Callable

Reference to a method that is called to handle e.g. a sub-command.

class pyTooling.Attributes.ArgParse.KeyValueFlag.LongKeyValueFlag[source]

Inheritance

Inheritance diagram of LongKeyValueFlag

__init__(long=None, dest=None, help=None)[source]

The constructor expects positional (*args), the destination parameter name dest and/or named parameters (**kwargs) which are passed to add_argument().

To implement a switch argument, the following named parameters are predefined:

  • action="store_const"

  • const=True

  • default=False

This implements a boolean parameter passed to the handler method.

Parameters:
  • long (str | None)

  • dest (str | None)

  • help (str | None)

property Args: Tuple

A tuple of additional positional parameters (*args) passed to the attribute. These additional parameters are passed without modification to ArgumentParser.

classmethod GetAttributes(method, includeSubClasses=True)

Returns attached attributes of this kind for a given method.

Parameters:
Return type:

Tuple[Attribute, ...]

Returns:

Raises:

TypeError

classmethod GetClasses(scope=None, subclassOf=None)

Return a generator for all classes, where this attribute is attached to.

The resulting item stream can be filtered by:
  • scope - when the item is a nested class in scope scope.

  • subclassOf - when the item is a subclass of subclassOf.

Parameters:
Return type:

Generator[TypeVar(TAttr, bound= Attribute), None, None]

Returns:

A sequence of classes where this attribute is attached to.

classmethod GetFunctions(scope=None)

Return a generator for all functions, where this attribute is attached to.

The resulting item stream can be filtered by:
  • scope - when the item is a nested class in scope scope.

Parameters:

scope (Optional[Type]) – Undocumented.

Return type:

Generator[TypeVar(TAttr, bound= Attribute), None, None]

Returns:

A sequence of functions where this attribute is attached to.

classmethod GetMethods(scope=None)

Return a generator for all methods, where this attribute is attached to.

The resulting item stream can be filtered by:
  • scope - when the item is a nested class in scope scope.

Parameters:

scope (Optional[Type]) – Undocumented.

Return type:

Generator[TypeVar(TAttr, bound= Attribute), None, None]

Returns:

A sequence of methods where this attribute is attached to.

property Handler: Callable

Returns the handler method.

property KWArgs: Dict

A dictionary of additional named parameters (**kwargs) passed to the attribute. These additional parameters are passed without modification to ArgumentParser.

static _AppendAttribute(entity, attribute)

Append an attribute to a language entity (class, method, function).

Hint

This method can be used in attribute groups to apply multiple attributes within __call__ method.

class GroupAttribute(Attribute):
  def __call__(self, entity: Entity) -> Entity:
    self._AppendAttribute(entity, SimpleAttribute(...))
    self._AppendAttribute(entity, SimpleAttribute(...))

    return entity
Parameters:
Raises:

TypeError – If parameter ‘entity’ is not a class, method or function.

Return type:

None

__call__(entity)

Attributes get attached to an entity (function, class, method) and an index is updated at the attribute for reverse lookups.

Parameters:

entity (TypeVar(Entity, bound= Union[Type, Callable])) – Entity (function, class, method), to attach an attribute to.

Return type:

TypeVar(Entity, bound= Union[Type, Callable])

Returns:

Same entity, with attached attribute.

Raises:

TypeError – If parameter ‘entity’ is not a function, class nor method.

_classes: ClassVar[List[Any]] = []

List of classes, this Attribute was attached to.

_functions: ClassVar[List[Any]] = []

List of functions, this Attribute was attached to.

_methods: ClassVar[List[Any]] = []

List of methods, this Attribute was attached to.

_scope: ClassVar[AttributeScope] = 7

Allowed language construct this attribute can be used with.

_handler: Callable

Reference to a method that is called to handle e.g. a sub-command.