Beispiel #1
0
def namedtuple(*args, **kwargs) -> type:
    """A shortcut for namedtuple

    You don't need to specify the typename, which will be fetched from
    the variable name.

    So instead of:
        >>> from collections import namedtuple
        >>> Name = namedtuple('Name', ['first', 'last'])

    You can do:
        >>> from varname import namedtuple
        >>> Name = namedtuple(['first', 'last'])

    Args:
        *args: arguments for `collections.namedtuple` except `typename`
        **kwargs: keyword arguments for `collections.namedtuple`
            except `typename`

    Returns:
        The namedtuple you desired.
    """
    warnings.warn(
        "Shortcut for namedtuple is deprecated and "
        "will be removed in 0.6.0. Use the standard way instead.",
        DeprecationWarning)
    typename = varname(raise_exc=True)
    return standard_namedtuple(typename, *args, **kwargs)
Beispiel #2
0
def namedtuple(*args, **kwargs):
    """A shortcut for namedtuple

    You don't need to specify the typename, which will be fetched from
    the variable name.

    So instead of:
    >>> from collections import namedtuple
    >>> Name = namedtuple('Name', ['first', 'last'])

    You can do:
    >>> from variables import namedtuple
    >>> Name = namedtuple(['first', 'last'])
    """
    typename = varname(raise_exc=True)
    return standard_namedtuple(typename, *args, **kwargs)