[Python-ideas] Re: Mapping unpacking assignment

2022-02-03 Thread Piper Thunstrom
On Thu, Feb 3, 2022 at 11:51 AM Yurii Karabas <1998uri...@gmail.com> wrote:
>
> I am proposing to add smth like JS destructing assignment to python.
> Basically, it will allow unpacking any mapping (should have __getitem__ and 
> keys() methods) into variables.
>
> Proposed syntax:
> ```
> m = {"a": 1, "b": 2, "c": 3, "d": 4}
>
> {a, b} = m # a: 1, b: 2
> {a, b, **rest} = m # a: 1, b: 2, rest: {c: 3, d: 4}
> ```

Can't you solve the same problem with structural pattern matching
against mappings?
https://www.python.org/dev/peps/pep-0622/#mapping-patterns

Piper Thunstrom
Senior Software Engineer/Open Source Maintainer
___
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/GBNGVK72CJE4AT52M6N5BWJIAX6UVNXX/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Add builtin function for min(max())

2020-07-04 Thread Piper Thunstrom
On Sat, Jul 4, 2020 at 8:29 AM Federico Salerno  wrote:
> On 04/07/2020 02:50, Christopher Barker wrote:
> > FWIW, numpy calls it "clip"
>
> I feel clip fits best with the idea of a collection to... clip. `clamp()` 
> would work with scalars, for which the word clip might not be clear at a 
> glance. While I have no strong feelings in favour of clamp, I do think it 
> would be better than clip (but maybe it's just my experience with CSS 
> speaking). As far as other options go, I agree with Mr D'Aprano's objection 
> to `minmax`, and I'd like to toss a possible `coerce` (similarly used in 
> Kotlin) into the hat. Maybe someone has better names in mind?

I'm going to back `clamp()` as that's what it's commonly referred to
in game dev circles. It's one of those functions that everyone in game
dev either memorizes the max(min()) pattern, writes their own, or is
blessed with a framework that provides it.

I agree with Dan that if I saw `coerce` I'd assume type coercion.

One benefit to `minmax` is that for those who have a good
autocomplete, it'll come up with either version of the `min(max())`
pattern and suggest a better usage if that's what they're after.

Largely, I think discoverability is a design constraint worth
considering, and clamp and minmax both have benefits in that regard.
(clamp being a common name for the scalar operation, and minmax for
search similarity to the existing functions.)

Piper Thunstrom

My public key is available at https://keybase.io/pathunstrom
Public key fingerprint: 8FF9 3F4E C447 55EC 4658 BDCC A57E A7A4 86D2 644F
___
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/STFLRLIB7ULXNXLB2MI6JESOFUR3NYWV/
Code of Conduct: http://python.org/psf/codeofconduct/