kwargproblems.pyx 490 Bytes
Newer Older
1 2 3 4
import sys

def test(**kw):
    """
5 6 7 8 9 10 11 12 13 14 15
    >>> d = {1 : 2}
    >>> test(**d)
    Traceback (most recent call last):
    TypeError: test() keywords must be strings
    >>> d
    {1: 2}
    >>> d = {}
    >>> test(**d)
    {'arg': 3}
    >>> d
    {}
Stefan Behnel's avatar
Stefan Behnel committed
16
    >>> d = {'arg' : 2} # this should be u'arg', but Py2 can't handle it...
17 18 19 20
    >>> test(**d)
    {'arg': 3}
    >>> d
    {'arg': 2}
21
    """
Stefan Behnel's avatar
Stefan Behnel committed
22 23 24 25
    if sys.version_info[0] >= 3:
        kw[u'arg'] = 3
    else:
        kw['arg'] = 3
26
    return kw