News for hackers. Stuff that matters.
Re:Strict Python function parameters by dec0dedab0de on Sunday January 23, 2022 @11:20AM (#30047359)
For your example I would do foo(Bar()) when I needed to run it without an existing object. Or make foo a method on the Bar class and do Bar().foo()

In general I just try my best to avoid immutable, or dynamic defaults, but sometimes they're necessary and I make that same if block at the top of the function. If I catch myself copy/pasting the same setup to multiple functions, then it might be time for a class or a decorator.

There are no comments on this comment yet.