This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author steven.daprano
Recipients TheComet, steven.daprano
Date 2019-05-03.22:32:37
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1556922758.44.0.507886615168.issue36788@roundup.psfhosted.org>
In-reply-to
Content
I doubt this is important enough to go into builtins, the only practical use-case I know of for this function is with numbers, so this could go in the math module.

But putting that aside, there are some other problems:

- it isn't clear that clamp() is meaningful for anything that could possibly need a key function;

- the behaviour you have for iterable arguments is inconsistent with the existing behaviour of min(max(x, a), b):

min(max('a string', 'd'), 'm')
=> returns 'd' not ['d', 'd', 'm', 'm', 'm', 'i', 'm', 'g']

- your iterable behaviour is easily done with a comprehension and doesn't need to be supported by the function itself

[clamp(x, a, b) for x in values]

- what do you intend clamp() to do with NAN arguments?

- for numbers, it is sometimes useful to do one-sided clamping, e.g. clamp(x, -1, ∞).

You should read over this thread here:

https://mail.python.org/pipermail/python-ideas/2016-July/041262.html
History
Date User Action Args
2019-05-03 22:32:38steven.dapranosetrecipients: + steven.daprano, TheComet
2019-05-03 22:32:38steven.dapranosetmessageid: <1556922758.44.0.507886615168.issue36788@roundup.psfhosted.org>
2019-05-03 22:32:38steven.dapranolinkissue36788 messages
2019-05-03 22:32:37steven.dapranocreate