On Mon, Jul 06, 2020 at 03:21:04AM +0100, Henk-Jaap Wagenaar wrote: > I do not agree clamp should be restricted to numeric values. I would expect > clamp to be agnostic to the specifics of floats/numbers and like sort > expect it to work for any values as long as they compare (using a dunder).
It is possible to write clamp so that it relies only on two things: - the bounds must support equality and less than; - the value must support less than. That is pretty much as general as it gets. I think that it is okay to document clamp as *intended* for numbers but allow it to be used for non-numbers, similar to the builtin sum(). (Although sum needs to be tricked into supporting strings.) Four years ago, there was strong opposition to giving the bounds default values. I think the consensus at the time was that it is okay to explicitly provide "unbounded" arguments (whether you spell them as infinities, NANs, or None) but you should have to explicitly do so: clamp(x) just reads poorly. I concur with that argument -- or at least, I don't disagree strongly enough to argue against it. This is why the implementation I posted earlier accepts None as bounds, but doesn't give them defaults. -- Steven _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/CKL734WLAZ26OWPJHCTCM2QIDCLFH622/ Code of Conduct: http://python.org/psf/codeofconduct/