5.0.6 seems to have broken the length of args again
dschult opened this issue · 4 comments
The trouble with default values for args was fixed from 5.0.4. to 5.0.5 but has broken again between 5.0.5 and 5.0.6.
These releases are not tagged in the repo so it is hard to tell what has changed that might affect this.
Should fix()
include a line like ba.apply_defaults()
?
Damn, I removed the apply_defaults since it seemed useless with the tests that I added in #108 :-(
Clearly I lack another test. Can you submit a test sensitive to the issue?
Here's a test showing trouble on v5.0.6
def listify(argument_indx):
@decorator.decorator
def _listify(func, *args, **kw):
new_args = list(args)
new_args[argument_indx] = [args[argument_indx]]
return func(*new_args, **kw)
return _listify
@listify(2)
def f(a, b, c=None):
assert type(c) == list
pytest.raises(IndexError, f, 0, 1)
# or just run f(0, 1) and get an IndexError
If you'd prefer this in a PR I can do that. Thanks!
It is fixed now. Sorry for the inconvenience. BTW, since version 4 we have decorator factories, so you can flatten your nested decorator as follows:
@decorator.decorator
def listify(func, index=0, *args, **kw):
new_args = list(args)
new_args[index] = args[index]
return func(*new_args, **kw)
@listify(index=2)
def f(a, b, c=None):
assert type(c) == list
Then you must use the call syntax listify(index=2)
and not listify(2)
but I see that as an improvement in legibility.
Excellent -- And thanks for that tip! I will use it. :}