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 don't recall neither what was the "conclusion" for NaN.
clamp(5, nan, nan)clamp(5, 0, nan)clamp(5, nan, 10)clamp(nan, 0, 10)clamp(nan, 5, 5)
>>> max(1, nan)1>>> max(nan, 1)nan>>> max(1.0, 1)1.0>>> max(1, 1.0)1
clamp(5, min_val=0)
clamp('foo', min_val='aaa') # expect "lexical clamping">>> min(max("aaa", "foo"), float('inf'))Traceback (most recent call last):File "<stdin>", line 1, in <module>TypeError: unorderable types: float() < str()>>> min(max("aaa", "foo"), None)Traceback (most recent call last):File "<stdin>", line 1, in <module>TypeError: unorderable types: NoneType() < str()>>> min(max("aaa", "foo"), "zzz")'foo'