>>>>> "David" == David Reiss (JIRA) <[email protected]> writes:
David> And it prints 1, 0. I think this needs to be avoided. The two best
David> solutions I can come up with are...
David> 1/ Default everything (at least non-scalars) to None, and make the
David> body of the __init__ say "if foo is None: foo = DEFAULT". The
David> downside is that it becomes impossible to override a default value
David> with None (in the constructor).
David> 2/ Take **kwargs. The downside is that it is less self-documenting.
David> Also, I think we would want to write code to throw an exception if
David> someone specified an invalid field.
David> Thoughts?
A simple way around this is to write
_default = object()
def func(x=_default):
if x = _default:
x = DEFAULT
You can use the same _default object for all args of this type in the same
file. This is a fairly well-known approach to this problem. The only
possible downside is someone deliberately reaching into the file to pass
_default as an arg, but in that case they get what they asked for...
Terry