[issue36788] Add clamp() function to builtins

2020-07-28 Thread Mark Dickinson


Mark Dickinson  added the comment:

Another python-ideas thread, from 2016: 
https://mail.python.org/archives/list/python-id...@python.org/thread/EHZAXE4P2VOT3CE4H6SNDPDASW7H2CGS/

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36788] Add clamp() function to builtins

2020-07-28 Thread Mark Dickinson


Mark Dickinson  added the comment:

#41408 was closed as a duplicate of this issue

See also the recent discussion on python-ideas at 
https://mail.python.org/archives/list/python-id...@python.org/thread/KWAOQFSV3YJYQV2Y5JXGXFCXHJ3WFLRS/#KWAOQFSV3YJYQV2Y5JXGXFCXHJ3WFLRS

That discussion has petered out without a clear consensus. The next step would 
likely be for an interested party to put together a PEP.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36788] Add clamp() function to builtins

2019-12-22 Thread Mark Dickinson


Mark Dickinson  added the comment:

> Maybe port this discussion over python-ideas and after the resolution open it 
> again?

Sounds good to me. Adding a new builtin function is a big deal that would 
likely need a PEP. I'm not keen on adding something like this to the math 
module, either, when it's so simple to construct from max and min.

Closing as rejected here; it can be re-opened if there's a strong consensus for 
adding it on the ideas list.

--
nosy: +mark.dickinson
resolution:  -> rejected
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36788] Add clamp() function to builtins

2019-12-21 Thread Batuhan


Batuhan  added the comment:

Should this issue stay? Maybe port this discussion over python-ideas and after 
the resolution open it again?

--
nosy: +BTaskaya

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36788] Add clamp() function to builtins

2019-05-10 Thread Terry J. Reedy


Change by Terry J. Reedy :


--
versions: +Python 3.8

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36788] Add clamp() function to builtins

2019-05-03 Thread Steven D'Aprano

Steven D'Aprano  added the comment:

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

--
nosy: +steven.daprano

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36788] Add clamp() function to builtins

2019-05-03 Thread TheComet


TheComet  added the comment:

I have implemented it on my branch here: 
https://github.com/TheComet/cpython/blob/fix-issue-36788/Python/bltinmodule.c

It still needs further testing and I haven't leak checked it properly.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36788] Add clamp() function to builtins

2019-05-03 Thread TheComet


New submission from TheComet :

It would be nice to have a clamp() builtin in addition to min() and max() so 
one can type e.g. "clamp(value, 2, 5)" instead of having to type 
"min(max(value, 5), 2)".

--
components: Library (Lib)
messages: 341358
nosy: TheComet
priority: normal
severity: normal
status: open
title: Add clamp() function to builtins
type: enhancement

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com