_casts module

Note

This module is imports as from .. import _casts. This means that you must use ezbotf.argumentparser._casts.ArgTypeCast as example.

Defines base for type-casting. Use it module if you define custom argument type-caster

ArgTypeCast

class ezbotf.argumentparser._casts.ArgTypeCast(type_: type)

Base class to help with the type-casting

Variables:

type – Type to cast in

__init__(type_: type)
Parameters:

type – Type for the type-casting

typecast(string: str) Any

Type-cast string to the given type

Parameters:

string – String to be type-casted

Returns:

Type-casted object

ListCast

class ezbotf.argumentparser._casts.ListCast(splitter: str = ', ', values_type: ~ezbotf.argumentparser._casts.ArgTypeCast = <ezbotf.argumentparser._casts.ArgTypeCast object>)

Type-cast a string to the list

Variables:
  • splitter – Splitter to use

  • values_type – Type to type-cast in values of list

__init__(splitter: str = ', ', values_type: ~ezbotf.argumentparser._casts.ArgTypeCast = <ezbotf.argumentparser._casts.ArgTypeCast object>)
Parameters:
  • splitter – String splitter

  • values_type – Type to cast the values of the list

typecast(string: str) list[Any]

Type-cast string to the list

Parameters:

string – String to be type-casted

Returns:

Type-casted list object

DictCast

class ezbotf.argumentparser._casts.DictCast(splitter: str = ', ', kv_splitter: str = '=', temp_char: str = '\uffff', key_type: ~ezbotf.argumentparser._casts.ArgTypeCast = <ezbotf.argumentparser._casts.ArgTypeCast object>, values_type: ~ezbotf.argumentparser._casts.ArgTypeCast = <ezbotf.argumentparser._casts.ArgTypeCast object>)

Type-cast a string to the dict

Variables:
  • splitter – Splitter to split the (key=value) pairs

  • kv_splitter – Splitter to split the key and value

  • temp_char – Temp char to replace the ‘==’ with it and back

  • key_type – Type to type-cast the keys

  • values_type – Type to type-cast the values

__init__(splitter: str = ', ', kv_splitter: str = '=', temp_char: str = '\uffff', key_type: ~ezbotf.argumentparser._casts.ArgTypeCast = <ezbotf.argumentparser._casts.ArgTypeCast object>, values_type: ~ezbotf.argumentparser._casts.ArgTypeCast = <ezbotf.argumentparser._casts.ArgTypeCast object>)
Parameters:
  • splitter – Splitter to split the (key=value) pairs

  • kv_splitter – Splitter to split the key and value

  • temp_char – Temp char to replace the ‘==’ with it and back

  • key_type – Type to type-cast the keys

  • values_type – Type to type-cast the values

typecast(string: str) dict[Any, Any]

Type-cast string to the dict

Parameters:

string – String to be type-casted

Returns:

Type-casted dict object

BoolCast

class ezbotf.argumentparser._casts.BoolCast(true_list: list[str] | None = None, false_list: list[str] | None = None, match_case: bool = False)

Type-cast a string to the bool

Variables:
  • true_list – List with the true string variants

  • false_list – List with the false string variants

  • match_case – Match case of the string

__init__(true_list: list[str] | None = None, false_list: list[str] | None = None, match_case: bool = False)
Parameters:
  • true_list – List with the true string variants

  • false_list – List with the false string variants

  • match_case – Match case of the string

typecast(string: str) bool

Type-cast string to the given type

Parameters:

string – String to be type-casted

Returns:

Type-casted bool object

Raises:

ArgumentTypeCastingError – When string isn’t have in the true/false list