When I have needed this I have added a separate <name>_factory keyword argument to my function - so the user can specify a value to <name> or a callable to <name>_factory with the doc string clearly spelling out the semantics - and what happens if neither is passed - yes another argument but the semantics are entirely clear. The other option where having a default value of a function doesn’t ever make sense is to assume that if a callable is passed then it must be a factory. So you can do an iscallable check -- Anthony Flury email : Anthony.flury@btinternet.com Twitter : @TonyFlury
On 11 Aug 2020, at 14:41, William Pickard
wrote: What you're running into is how Python handles default arguments.
Take this for example: def my_func(seq=[]): print(seq) seq.append(42) print(seq)
my_func() # [] # [42]
my_func() # [42] # [42, 42] _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-leave@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/DJLTF3... Code of Conduct: http://python.org/psf/codeofconduct/