On Sat, Jul 04, 2020 at 01:01:15AM +0100, MRAB wrote: > Should it raise an exception if minimum > maximum?
I think there are only two reasonable answers to this: - raise an exception if the lower bounds is greater than the upper bounds ("errors should never pass silently"); - or Do What I Mean by swapping them if they are in the wrong order: if lower > upper: lower, upper = upper, lower I'm +1 on raising and about +0.00001 on DWIM. People who have read my posts on this mailing list in the past may remember that I am usually very suspicious of, if not hostile to, DWIM functions, but in this case I think it's harmless. This is what numpy does if you get the order wrong: py> import numpy as np py> np.clip(5, 1, 10) # This is correct. 5 py> np.clip(5, 10, 1) # WOT? 10 Silently returning garbage is not, in my opinion, acceptable here. -- 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/NJBJQSOCXBQ5PGXIP2Y5SFBQ25K46ZLC/ Code of Conduct: http://python.org/psf/codeofconduct/