|
| 1 | +## v0.6.2 |
| 2 | +- Remove argument `full` for `nameof`, use `vars_only` instead. When `vars_only=False`, source of the argument returned. |
| 3 | + ```python |
| 4 | + # before: |
| 5 | + nameof(a.b, full=True) # 'a.b' |
| 6 | + nameof(x[0], full=True) # unable to fetch |
| 7 | + # after (requires asttoken): |
| 8 | + nameof(a.b, vars_only=False) # 'a.b' |
| 9 | + nameof(x[0], vars_only=False) # 'x[0]' |
| 10 | + ``` |
| 11 | +- Add argument `frame` to `argname`, so that it can be wrapped. |
| 12 | + ```python |
| 13 | + def argname2(arg, *more_args): |
| 14 | + return argname(arg, *more_args, frame=2) |
| 15 | + ``` |
| 16 | +- Allow `argname` to fetch the source of variable keyword arguments (`**kwargs`), which will be an empty dict (`{}`) when no keyword arguments passed. |
| 17 | + ```python |
| 18 | + def func(a, **kwargs): |
| 19 | + return argname(a, kwargs) |
| 20 | + # before: |
| 21 | + func(x) # raises error |
| 22 | + # after: |
| 23 | + func(x) # returns ('x', {}) |
| 24 | + ``` |
| 25 | +- Add argument `pos_only` to `argname` to only match the positional arguments |
| 26 | + ```python |
| 27 | + # before |
| 28 | + def func(a, b=1): |
| 29 | + return argname(a) |
| 30 | + func(x) # 'x' |
| 31 | + func(x, b=2) # error since 2 is not ast.Name |
| 32 | + |
| 33 | + # after |
| 34 | + def func(a, b=1): |
| 35 | + return argname(a, pos_only=True) |
| 36 | + func(x) # 'x' |
| 37 | + func(x, b=2) # 'x' |
| 38 | + ``` |
| 39 | +- Parse the arguments only if needed |
| 40 | + ```python |
| 41 | + # before |
| 42 | + def func(a, b): |
| 43 | + return argname(a) |
| 44 | + func(x, 1) # NonVariableArgumentError |
| 45 | + |
| 46 | + # after |
| 47 | + func(x, 1) # 'x' |
| 48 | + ``` |
| 49 | +- Allow variable positional arguments for `argname` so that `argname(*args)` is allowed |
| 50 | + ```python |
| 51 | + # before |
| 52 | + def func(arg, *args): |
| 53 | + return argname(arg, args) # *args not allowed |
| 54 | + x = y = 1 |
| 55 | + func(x, y) # ('x', ('y', 1)) |
| 56 | + |
| 57 | + # after |
| 58 | + def func(arg, *args): |
| 59 | + return argname(arg, *args) |
| 60 | + x = y = 1 |
| 61 | + func(x, y) # ('x', 'y') |
| 62 | + ``` |
| 63 | +- Add `vars_only` (defaults to `False`) argument to `helpers.debug` so source of expression becomes available |
| 64 | + ```python |
| 65 | + a=1 |
| 66 | + debug(a+a) # DEBUG: a+a=2 |
| 67 | + ``` |
| 68 | + |
1 | 69 | ## v0.6.1
|
2 | 70 | - Add `argname` to retrieve argument names/sources passed to a function
|
3 | 71 |
|
|
0 commit comments