| Conditions | 1 |
| Total Lines | 18 |
| Code Lines | 13 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | import functools |
||
| 5 | def pep_570_when(func): |
||
| 6 | signature = inspect.signature(func) |
||
| 7 | non_kwargs_only = dict(signature.parameters) |
||
| 8 | kwargs = non_kwargs_only.pop(tuple(non_kwargs_only)[-1]) |
||
| 9 | |||
| 10 | parameters = [ |
||
| 11 | param.replace(kind=inspect.Parameter.POSITIONAL_ONLY) |
||
| 12 | for param in non_kwargs_only.values() |
||
| 13 | ] |
||
| 14 | |||
| 15 | parameters.append(kwargs.replace(kind=inspect.Parameter.VAR_KEYWORD)) |
||
| 16 | |||
| 17 | @functools.wraps(func) |
||
| 18 | def wrapped(*args, **kwargs): |
||
| 19 | return func(*args, kwargs) |
||
| 20 | |||
| 21 | wrapped.__signature__ = signature.replace(parameters=parameters) |
||
| 22 | return wrapped |
||
| 23 |