
Oct. 28, 2015
12:57 a.m.
On 10/27/2015 7:36 PM, Steven D'Aprano wrote:
The unobvious and ugly way is to put the calculation in the function declaration as a default value:
def spam(SENTINEL=next_prime_number(2**512)): ...
which complicates the function signature and risks errors if the caller accidentally calls the function with too many arguments.
Making constant names keyword only avoids the 'too many arguments' problem.
def spam(*, _SETINAL=object): pass
spam(1) Traceback (most recent call last): File "<pyshell#3>", line 1, in <module> spam(1) TypeError: spam() takes 0 positional arguments but 1 was given
Writing 'spam(_SETINAL=3)' would not be an accident ;-) -- Terry Jan Reedy