Dynamic evaluation of function argument list initializer

You may want to look into the sentinels PEP (661, IIRC?), for these particular cases.

I also recommend looking at pylint and flake8-bugbear , if you’re not already familiar with those tools. Both have lints for special cases in which mutable arg defaults can surprise new Python developers.


I wouldn’t tend to argue for late binding defaults starting from the premise that the current behavior is confusing and that adding late binding would improve that.

I think the early binding behavior can surprise people, but late binding defaults actually make things more confusing for beginners. Novice Python developers may not understand that some special marker significantly changes the meaning of a default. To me, the argument in favor of it is “for experienced folks, this is a useful way of encoding ideas which currently are very verbose”.
(I think 671 is really interesting, by the way. But my support for it might stem from a different perspective.)

1 Like