Complete worked example
python
def inspect_example(value, mode):
def scale(amount, /, *, factor=2):
return amount * factor
if mode == 'positional':
return scale(value, factor=3)
if mode == 'keyword':
try:
return scale(amount=value, factor=3)
except TypeError:
return 'positional-only rejected'
raise ValueError('unknown mode')- Reasoning
- Read the nested scale function before following the dispatcher. A positional request passes value as the first argument and factor as a named option, producing twelve for four and three. The keyword request names amount and is rejected before the function body executes.