Far be it from me to damp your enthusiasm, but it seems to me that the functionality of a clamp function is so simple, and yet has so many possible variations, that it's not worth providing it.
I.e., it's probably quicker for someone to write their own version (typically <= 4 lines of code) than to
look up the library version
read *and understand* its specification
decide whether it's suitable for their use case
maybe: decide that it isn't (or they don't understand it) and write their own one anyway.
A custom version can also be optimised for the particular use case.
On 13/08/2016 01:14, Steven D'Aprano wrote:
On Sat, Aug 13, 2016 at 01:25:58AM +0200, Victor Stinner wrote:
I tried to follow this discussion and I still to understand why my proposition of "def clamp(min_val, value, max_val): return min(max(min_val, value), max_val)" is not good. I expect that a PEP replies to this question without to read the whole thread :-)
I said I would write up a summary, and I will. If you want to call it a PEP, I'm okay with that. I won't forget your proposal either :-)