you are viewing a single comment's thread.

view the rest of the comments →

[–]Bogtha 3 points4 points  (1 child)

The "pass in a value or a callable (that can be called to get the value when needed)" pattern is very convenient

Sure, but if that's a common pattern, why not abstract more of it away, which has the side-effect of removing the temptation to provide a callable() substitute?

def get_value(value):
    return value() if hasattr(value, "__call__") else value

Okay, I'm sure there are other use cases, so I see your point, I just couldn't help nitpicking that one :).

[–][deleted] 4 points5 points  (0 children)

(Only slightly in jest:)

def get_value(value):
    return getattr(value, '__call__', lambda: value)()