Issue #21 open

Bare asterisk in arguments list

Joe Amenta
repo owner created an issue

{{{

!python

def spam(ham, , eggs='food', *kwargs): pass }}}

The above code is legal in Python 3, but not in Python 2.

This could possibly fix to:

{{{

!python

def spam(ham, **kwargs): if 'eggs' in kwargs: eggs = kwargs['eggs'] del kwargs['eggs'] else: eggs = 'food' pass }}}

Comments (6)

  1. Joe Amenta reporter

    This is a consequence of the following that also works in Python 3 but not Python 2:

    def spam(ham, *args, eggs, **kwargs):
        pass
    

    Basically, keyword-only arguments need a makeover.

  2. Łukasz Langa
    • changed status to new
    • marked as bug

    It works but breaks docstrings:

    def func(obligatory, *, other=' ', arguments=''):
        """func(obligatory, [other, arguments]) -> ponies
    
        Returns ponies for the given `obligatory` argument. Optional `other`
        `arguments` may be passed."""
    
        return "{} ponies.{}{}".format(obligatory, other, arguments)
    
    print(func.__doc__)
    print()
    print(func("Pink", arguments="Not yours."))
    

    is converted to

    def func(obligatory, **_3to2kwargs):
        if 'arguments' in _3to2kwargs: arguments = _3to2kwargs['arguments']; del _3to2kwargs['arguments']
        else: arguments = u''
        if 'other' in _3to2kwargs: other = _3to2kwargs['other']; del _3to2kwargs['other']
        else: other = u' '
        u"""func(obligatory, [other, arguments]) -> ponies
    
        Returns ponies for the given `obligatory` argument. Optional `other`
        `arguments` may be passed."""
    
        return u"{} ponies.{}{}".format(obligatory, other, arguments)
    
    print func.__doc__
    print
    print func(u"Pink", arguments=u"Not yours.")
    

    Now func.__doc__ is None.

  3. Log in to comment