[Python-ideas] Re: Equality between some of the indexed collections

2020-05-05 Thread jdveiga
Raymond Hettinger wrote: > > On May 3, 2020, at 6:19 PM, Steven D'Aprano [email protected] wrote: > > frozenset and set make a counterexample: > > frozenset({1}) == {1} > > True > > Nice catch! That's really interesting. Is there reasoning > > behind > > frozenset({1}) == {1} but [1] != (1,), or

[Python-ideas] Re: Equality between some of the indexed collections

2020-05-05 Thread Alex Hall
On Tue, May 5, 2020 at 7:36 AM Raymond Hettinger < [email protected]> wrote: > >> Isn't a tuple essentially just a frozenlist? I know the intended > >> semantics of tuples and lists tend to be different, but I'm not sure > that's > >> relevant. > > > In terms of API, it might look that w

[Python-ideas] Re: zip(x, y, z, strict=True)

2020-05-05 Thread Paul Moore
On Tue, 5 May 2020 at 07:22, Christopher Barker wrote: > In any case, you seem to making the argument that a few of us are putting > forward: yes, a flag on zip() is likely to get more use than a function in > itertools. Thanks for the support :-) I'd like to add my voice to the people saying

[Python-ideas] Re: Equality between some of the indexed collections

2020-05-05 Thread Steven D'Aprano
On Tue, May 05, 2020 at 09:34:28AM -, [email protected] wrote: > `(frozenset() == set()) is True` shocked me. > > According to wikipedia https://en.wikipedia.org/wiki/Equality_(mathematics): > "equality is a relationship between two quantities or, more generally two > mathematical expressio

[Python-ideas] Re: Auto-assign attributes from __init__ arguments

2020-05-05 Thread Steven D'Aprano
On Tue, May 05, 2020 at 04:05:20AM -, Brandt Bucher wrote: > > We should have a mechanism that collects the current function or method's > > parameters into a dict, similar to the way locals() returns all local > > variables. > > Maybe I'm missing something here, but how about... `locals`? I

[Python-ideas] Re: zip(x, y, z, strict=True)

2020-05-05 Thread Henk-Jaap Wagenaar
I feel like that argument is flawed. I cannot think of another good example (I am sure there are plenty!) but there is a big difference for discoverability between: A function that does something *different* and functionality does not exist in a built-in (or whatever namespace you are considering)

[Python-ideas] Re: zip(x, y, z, strict=True)

2020-05-05 Thread Rhodri James
On 05/05/2020 13:12, Henk-Jaap Wagenaar wrote: A function that is a "safer" version in some "edge case" (not extra functionality but better error handling basically) but that does otherwise work as expected is not something one will search for automatically. This is zip versus zip-with-strict-tru

[Python-ideas] Re: Auto-assign attributes from __init__ arguments

2020-05-05 Thread Chris Angelico
On Tue, May 5, 2020 at 10:08 PM Steven D'Aprano wrote: > > On Tue, May 05, 2020 at 04:05:20AM -, Brandt Bucher wrote: > > It's a fairly common idiom to just collect `locals()` on the first > > line of a function or method with lots of arguments > > Indeed, but it's that requirement that it mus

[Python-ideas] Re: zip(x, y, z, strict=True)

2020-05-05 Thread Henk-Jaap Wagenaar
Brandt's example with ast in the stdlib I think is a pretty good example of this. On Tue, 5 May 2020 at 13:27, Rhodri James wrote: > On 05/05/2020 13:12, Henk-Jaap Wagenaar wrote: > > A function that is a "safer" version in some "edge case" (not extra > > functionality but better error handling

[Python-ideas] Re: Auto-assign attributes from __init__ arguments

2020-05-05 Thread Alex Hall
Perhaps we should take the energy that is going into this thread and direct it towards supporting keyword-only arguments in dataclasses, a discussion which is apparently struggling: https://github.com/python/cpython/pull/6238#issuecomment-584579729 On Mon, May 4, 2020 at 10:49 PM Lewis Ball wrote

[Python-ideas] Re: Auto-assign attributes from __init__ arguments

2020-05-05 Thread Steven D'Aprano
On Tue, May 05, 2020 at 02:55:24PM +0200, Alex Hall wrote: > Perhaps we should take the energy that is going into this thread and direct > it towards supporting keyword-only arguments in dataclasses, a discussion > which is apparently struggling: Why? How are dataclasses relevant (don't assume it

[Python-ideas] Re: Auto-assign attributes from __init__ arguments

2020-05-05 Thread Alex Hall
On Tue, May 5, 2020 at 3:14 PM Steven D'Aprano wrote: > On Tue, May 05, 2020 at 02:55:24PM +0200, Alex Hall wrote: > > > Perhaps we should take the energy that is going into this thread and > direct > > it towards supporting keyword-only arguments in dataclasses, a discussion > > which is apparen

[Python-ideas] Passing Arguments Through Thin Wrappers (was : Auto-assign attributes from __init__ arguments)

2020-05-05 Thread Dan Sommers
On Tue, 5 May 2020 23:06:39 +1000 Steven D'Aprano wrote: > ... help me solve the DRY problem for module-level functions: > > def function(spam, eggs, cheese, aardvark): > do stuff > call _private_function(spam, eggs, cheese, aardvark) > > since this bites me about twice as o

[Python-ideas] Re: zip(x, y, z, strict=True)

2020-05-05 Thread Steven D'Aprano
On Mon, Apr 27, 2020 at 01:39:19PM -0700, Christopher Barker wrote: > Can you think of a single case where a zip_equal() (either pre-exisiting or > roll your own) would not work, but the concretizing version would? That's easy: if the body of your zip-handling function has side-effects which mus

[Python-ideas] Re: Equality between some of the indexed collections

2020-05-05 Thread jdveiga
Steven D'Aprano wrote: > On Tue, May 05, 2020 at 09:34:28AM -, [email protected] wrote: > > (frozenset() == set()) is True shocked > > me. > > According to wikipedia https://en.wikipedia.org/wiki/Equality_(mathematics): > > "equality is a relationship between two quantities or, more generally t

[Python-ideas] Re: Passing Arguments Through Thin Wrappers (was : Auto-assign attributes from __init__ arguments)

2020-05-05 Thread Steven D'Aprano
Here is a quick and dirty proof of concept: from inspect import stack, Signature def parameters(): caller = stack()[2][0].f_globals[stack()[1][3]] sig = Signature.from_callable(caller) vars = stack()[1][0].f_locals return sig.bind(**vars).arguments d

[Python-ideas] Re: Passing Arguments Through Thin Wrappers (was : Auto-assign attributes from __init__ arguments)

2020-05-05 Thread Dominik Vilsmeier
On 05.05.20 15:35, Dan Sommers wrote: On Tue, 5 May 2020 23:06:39 +1000 Steven D'Aprano wrote: ... help me solve the DRY problem for module-level functions: def function(spam, eggs, cheese, aardvark): do stuff call _private_function(spam, eggs, cheese, aardvark) since

[Python-ideas] Re: Passing Arguments Through Thin Wrappers (was : Auto-assign attributes from __init__ arguments)

2020-05-05 Thread Barry Scott
> On 5 May 2020, at 15:38, Steven D'Aprano wrote: > > Here is a quick and dirty proof of concept: > > >from inspect import stack, Signature > >def parameters(): >caller = stack()[2][0].f_globals[stack()[1][3]] >sig = Signature.from_callable(caller) >vars = st

[Python-ideas] Re: zip(x, y, z, strict=True)

2020-05-05 Thread Rhodri James
On 05/05/2020 13:53, Henk-Jaap Wagenaar wrote: Brandt's example with ast in the stdlib I think is a pretty good example of this. On Tue, 5 May 2020 at 13:27, Rhodri James wrote: On 05/05/2020 13:12, Henk-Jaap Wagenaar wrote: A function that is a "safer" version in some "edge case" (not extra

[Python-ideas] Re: zip(x, y, z, strict=True)

2020-05-05 Thread Chris Angelico
On Wed, May 6, 2020 at 1:44 AM Rhodri James wrote: > > On 05/05/2020 13:53, Henk-Jaap Wagenaar wrote: > > Brandt's example with ast in the stdlib I think is a pretty good example of > > this. > > > > On Tue, 5 May 2020 at 13:27, Rhodri James wrote: > > > >> On 05/05/2020 13:12, Henk-Jaap Wagenaar

[Python-ideas] Re: zip(x, y, z, strict=True)

2020-05-05 Thread David Mertz
I have no idea whether a flag on zip() or a function in itertools would get MORE USE. I *ABSOLUTELY* think it is an anti-goal to get more use for its own sake though. I'm +1 on a new function in itertools, maybe +0 or maybe -0 on a flag. But I only want APPROPRIATE USE in any case. The API conv

[Python-ideas] Re: zip(x, y, z, strict=True)

2020-05-05 Thread Henk-Jaap Wagenaar
This is a straw man in regards to backwards compatibility. This particular (sub)thread is about whether if this zip-is-strict either as a separate name or a Boolean flag or some other flag of zip should be a built-in or be in e.g. itertools. It is not about breaking backwards compatibility (presum

[Python-ideas] Re: zip(x, y, z, strict=True)

2020-05-05 Thread Henk-Jaap Wagenaar
But you care about your input, you can do so by setting strict=True (if that's the road we go down), and unlike what others have said, the IDE I use (pycharm) would tell me that flag exists as I type "zip" and so I'd be more likely to use it than if it was in itertools/... On Tue, 5 May 2020, 16:4

[Python-ideas] Re: zip(x, y, z, strict=True)

2020-05-05 Thread Rhodri James
On 05/05/2020 17:26, Henk-Jaap Wagenaar wrote: This is a straw man in regards to backwards compatibility. This particular (sub)thread is about whether if this zip-is-strict either as a separate name or a Boolean flag or some other flag of zip should be a built-in or be in e.g. itertools. It is n

[Python-ideas] Re: zip(x, y, z, strict=True)

2020-05-05 Thread Steven D'Aprano
On Tue, May 05, 2020 at 05:26:02PM +0100, Henk-Jaap Wagenaar wrote: > This is a straw man in regards to backwards compatibility. This particular > (sub)thread is about whether if this zip-is-strict either as a separate > name or a Boolean flag or some other flag of zip should be a built-in or be >

[Python-ideas] Re: zip(x, y, z, strict=True)

2020-05-05 Thread Steven D'Aprano
On Tue, May 05, 2020 at 05:28:08PM +0100, Henk-Jaap Wagenaar wrote: > But you care about your input, you can do so by setting strict=True (if > that's the road we go down), and unlike what others have said, the IDE I > use (pycharm) would tell me that flag exists as I type "zip" and so I'd be > mor

[Python-ideas] Re: zip(x, y, z, strict=True)

2020-05-05 Thread Henk-Jaap Wagenaar
On Tue, 5 May 2020, 18:24 Steven D'Aprano, wrote: > On Tue, May 05, 2020 at 05:26:02PM +0100, Henk-Jaap Wagenaar wrote: > > > This is a straw man in regards to backwards compatibility. This > particular > > (sub)thread is about whether if this zip-is-strict either as a separate > > name or a Bool

[Python-ideas] Re: zip(x, y, z, strict=True)

2020-05-05 Thread Chris Angelico
On Wed, May 6, 2020 at 3:25 AM Steven D'Aprano wrote: > Personally, I don't think Chris' backwards-compatibility argument is > strong. Technically adding a new keyword argument to a function is > backwards-incompatible, but we normally exclude that sort of change. Who > writes this? > > # This

[Python-ideas] Re: Equality between some of the indexed collections

2020-05-05 Thread Ethan Furman
On 05/05/2020 03:05 AM, Alex Hall wrote: On Tue, May 5, 2020 at 7:36 AM Raymond Hettinger mailto:[email protected]>> wrote: >> Isn't a tuple essentially just a frozenlist? I know the intended >> semantics of tuples and lists tend to be different, but I'm not sure that's

[Python-ideas] Re: zip(x, y, z, strict=True)

2020-05-05 Thread Christopher Barker
On Tue, May 5, 2020 at 9:20 AM David Mertz wrote: > I have no idea whether a flag on zip() or a function in itertools would > get MORE USE. I *ABSOLUTELY* think it is an anti-goal to get more use for > its own sake though. > I'm not sure anyone was suggesting that -- *maybe* Alex, but I think h

[Python-ideas] Re: zip(x, y, z, strict=True)

2020-05-05 Thread Christopher Barker
"If its builtin people will be more likely to use it, so we need to make > it builtin." > > This argument will apply to **literally** every function and class in > the standard library. But we are not talking adding a new builtin. > Firstly, we would have to agree that "maximizing the number o

[Python-ideas] Re: zip(x, y, z, strict=True)

2020-05-05 Thread Rhodri James
On 05/05/2020 21:03, Christopher Barker wrote: "If its builtin people will be more likely to use it, so we need to make it builtin." This argument will apply to **literally** every function and class in the standard library. But we are not talking adding a new builtin. Well, actually we ar

[Python-ideas] Re: Passing Arguments Through Thin Wrappers (was : Auto-assign attributes from __init__ arguments)

2020-05-05 Thread Lewis Ball
>from inspect import stack, Signature > >def parameters(): >caller = stack()[2][0].f_globals[stack()[1][3]] >sig = Signature.from_callable(caller) >vars = stack()[1][0].f_locals >return sig.bind(**vars).arguments This also doesn't work for me if a variable i

[Python-ideas] Re: Equality between some of the indexed collections

2020-05-05 Thread Greg Ewing
On 6/05/20 2:22 am, [email protected] wrote: However, if sets and frozensets are "are considered to be fundamentally the same kind of thing differentiated by mutability", as you said, why not tuples and lists? I think that can be answered by looking at the mathematical heritage of the types inv

[Python-ideas] Re: zip(x, y, z, strict=True)

2020-05-05 Thread Steven D'Aprano
Christopher's quoting is kinda messed up and I can't be bothered fixing it, sorry, so you'll just have to guess who said what :-) On Tue, May 05, 2020 at 01:03:30PM -0700, Christopher Barker wrote: > "If its builtin people will be more likely to use it, so we need to make > > it builtin." > > >

[Python-ideas] Re: Equality between some of the indexed collections

2020-05-05 Thread Henk-Jaap Wagenaar
On Wed, 6 May 2020 at 01:41, Greg Ewing wrote: > On 6/05/20 2:22 am, [email protected] wrote: > > However, if sets and frozensets are "are considered to be > > fundamentally the same kind of thing differentiated by mutability", > > as you said, why not tuples and lists? > > I think that can be an

[Python-ideas] Re: Equality between some of the indexed collections

2020-05-05 Thread Steven D'Aprano
On Wed, May 06, 2020 at 12:39:30PM +1200, Greg Ewing wrote: > On 6/05/20 2:22 am, [email protected] wrote: > >However, if sets and frozensets are "are considered to be > >fundamentally the same kind of thing differentiated by mutability", > >as you said, why not tuples and lists? > > I think that

[Python-ideas] Re: Equality between some of the indexed collections

2020-05-05 Thread Steven D'Aprano
On Wed, May 06, 2020 at 02:58:01AM +0100, Henk-Jaap Wagenaar wrote: > I don't think that is accurate to represent as a representation of "a > mathematician". The top voted answer here disagrees: > https://math.stackexchange.com/questions/122595/whats-the-difference-between-tuples-and-sequences >

[Python-ideas] Re: zip(x, y, z, strict=True)

2020-05-05 Thread Steven D'Aprano
On Tue, May 05, 2020 at 12:49:05PM -0700, Christopher Barker wrote: > Agreed, but discoverability is still something to be considered in the API. > ANd it seems that there are folks arguing that we specifically want this to > be less discoveble due to concerns of overuse. Which does not seem like