argh/assembling.py
def _guess(kwargs):
    """
    Adds types, actions, etc. to given argument specification.
    For example, ``default=3`` implies ``type=int``.

    :param arg: a :class:`argh.utils.Arg` instance
    """
    guessed = {}

    # Parser actions that accept argument 'type'
    TYPE_AWARE_ACTIONS = 'store', 'append'

    # guess type/action from default value
    value = kwargs.get('default')
    if value is not None:
        if isinstance(value, bool):
            if kwargs.get('action') is None:
                # infer action from default value
                guessed['action'] = 'store_false' if value else 'store_true'
        elif kwargs.get('type') is None:
            # infer type from default value
            # (make sure that action handler supports this keyword)
            if kwargs.get('action', 'store') in TYPE_AWARE_ACTIONS:
                guessed['type'] = type(value)

    # guess type from choices (first item)
    if kwargs.get('choices') and 'type' not in list(guessed) + list(kwargs):
        guessed['type'] = type(kwargs['choices'][0])

    return dict(kwargs, **guessed)
def _guess(kwargs):
    guessed = {}

    # Parser actions that accept argument 'type'
    TYPE_AWARE_ACTIONS = 'store', 'append'

    # guess type/action from default value
    value = kwargs.get('default')
    if value is not None:
        if isinstance(value, bool):
            if kwargs.get('action') is None:
                # infer action from default value
                guessed['action'] = 'store_false' if value else 'store_true'
        elif kwargs.get('type') is None:
            # infer type from default value
            # (make sure that action handler supports this keyword)
            if kwargs.get('action', 'store') in TYPE_AWARE_ACTIONS:
                guessed['type'] = type(value)

    # guess type from choices (first item)
    if kwargs.get('choices') and 'type' not in list(guessed) + list(kwargs):
        guessed['type'] = type(kwargs['choices'][0])

    return dict(kwargs, **guessed)
def _guess ( kwargs ) : guessed = { } # Parser actions that accept argument 'type' TYPE_AWARE_ACTIONS = 'store' , 'append' # guess type/action from default value value = kwargs . get ( 'default' ) if value is not None : if isinstance ( value , bool ) : if kwargs . get ( 'action' ) is None : # infer action from default value guessed [ 'action' ] = 'store_false' if value else 'store_true' elif kwargs . get ( 'type' ) is None : # infer type from default value # (make sure that action handler supports this keyword) if kwargs . get ( 'action' , 'store' ) in TYPE_AWARE_ACTIONS : guessed [ 'type' ] = type ( value ) # guess type from choices (first item) if kwargs . get ( 'choices' ) and 'type' not in list ( guessed ) + list ( kwargs ) : guessed [ 'type' ] = type ( kwargs [ 'choices' ] [ 0 ] ) return dict ( kwargs , * * guessed )
Adds types, actions, etc. to given argument specification.
    For example, ``default=3`` implies ``type=int``.

    :param arg: a :class:`argh.utils.Arg` instance
Adds types actions etc . to given argument specification . For example default = 3 implies type = int .