[Python-ideas] Re: Additional meanings for "in" operator and ability to customize implementation

2019-10-14 Thread Andrew Barnert via Python-ideas
On Oct 13, 2019, at 22:54, Chris Angelico wrote: > > Mathematically, what's the difference between '1' and '1+0j' (or > '1+0i')? The details depend on what foundations you use, but let’s go with the most common construction. The natural number 1 is defined as 0 U {0}. Because 0 is defined as {

[Python-ideas] Re: Resolve append/add API inconsistency between set and list

2019-10-14 Thread Serhiy Storchaka
14.10.19 09:54, Chris Angelico пише: On Mon, Oct 14, 2019 at 5:41 PM Serhiy Storchaka wrote: 14.10.19 03:47, Chris Angelico пише: Though a set.__setitem__() method might be helpful here. If you set an item to any truthy value, it is added to the set; set it to a falsy value and it will be dis

[Python-ideas] Re: Additional meanings for "in" operator and ability to customize implementation

2019-10-14 Thread Andrew Barnert via Python-ideas
Sorry, missed this part: On Oct 13, 2019, at 22:54, Chris Angelico wrote: isinstance(1, numbers.Complex) > True > > Explain the difference? `Complex` is an abstract type that defines an interface, which is loosely: supporting all the complex-arithmetic operators, properties like `real`,

[Python-ideas] Re: Additional meanings for "in" operator and ability to customize implementation

2019-10-14 Thread Chris Angelico
On Mon, Oct 14, 2019 at 7:04 PM Andrew Barnert wrote: > If you’re wondering whether integers are something you could define the laws > of complex algebra over, then no, it isn’t. For example, one of the laws is > that every number besides 0 has a multiplicative inverse, which obviously > isn’t

[Python-ideas] Re: Additional meanings for "in" operator and ability to customize implementation

2019-10-14 Thread Richard Musil
> > On Oct 13, 2019, at 22:54, Chris Angelico wrote: > > > > Mathematically, what's the difference between '1' and '1+0j' (or > > '1+0i')? > 1 is perfectly valid natural number, rational number (equivalent to 1/1), real number (equivalent to 1.0) and complex number (equivalent to 1.0+0.0i). Every

[Python-ideas] Re: Resolve append/add API inconsistency between set and list

2019-10-14 Thread Steven D'Aprano
On Sun, Oct 13, 2019 at 09:53:41PM -0400, David Mertz wrote: [in response to my comment] > > (don't you have an IDE with a refactor command for that?^1 ) > > ^1 I don't, so I'm not entirely unsympathetic to this argument. > > > > I really don't! > > It would be cool to have some keystrokes that

[Python-ideas] Re: Resolve append/add API inconsistency between set and list

2019-10-14 Thread Rhodri James
On 13/10/2019 20:20, Steve Jorgensen wrote: Failing fast is good, but it is also a very common case to want to add an item to a collection regardless of whether it is set-like or sequence-like. I have to say that for "a very common case" it's something that I've never needed. Never. Serious

[Python-ideas] Re: Why not accept lists or arbitrary iterables in str.endswith?

2019-10-14 Thread Steve Jorgensen
Andrew Barnert wrote: > On Oct 13, 2019, at 19:03, Steve Jorgensen [email protected] wrote: > > That makes a lot of sense. > > When you’re replying, it really helps to quote what you’re replying to. I > > have no > idea which of the messages in this thread you think makes sense (except that > it

[Python-ideas] Re: Add Scalar to collections.abc with str, bytes, etc. being both Scalar and Sequence (therefore also Container)

2019-10-14 Thread Steve Jorgensen
Chris Angelico wrote: > On Mon, Oct 14, 2019 at 8:48 AM Steve Jorgensen [email protected] wrote: [snip] > You want to drill down into all containers except strings, so why not > just say that? > Scalar = (str, bytes) A scalar is not just str or bytes though. It is also anything else that's not a

[Python-ideas] Re: Add Scalar to collections.abc with str, bytes, etc. being both Scalar and Sequence (therefore also Container)

2019-10-14 Thread Rhodri James
On 14/10/2019 12:13, Steve Jorgensen wrote: A scalar is not just str or bytes though. It is also anything else that's not a collection, so numbers, dates, booleans, and instances of any other classes (standard or custom) that are not collections. A string is just one of the few examples of someth

[Python-ideas] Re: Add Scalar to collections.abc with str, bytes, etc. being both Scalar and Sequence (therefore also Container)

2019-10-14 Thread Chris Angelico
On Mon, Oct 14, 2019 at 10:14 PM Steve Jorgensen wrote: > Assuming `Scalar` can't clean up every case we can imagine for this kind of > ambiguity can come up with doesn't mean it's not potentially very helpful. > After the discussion so far, I happen to still feel like this is a compelling > id

[Python-ideas] Re: Additional meanings for "in" operator and ability to customize implementation

2019-10-14 Thread Oscar Benjamin
On Mon, 14 Oct 2019 at 05:47, Andrew Barnert via Python-ideas wrote: > > `1 in complex` is _not_ mathematically true. Simplifying a bit, the elements > of the algebra of complex numbers are ordered pairs of real numbers, and `1` > is not a pair. When you’re working in, say, complex analysis, you

[Python-ideas] Re: Additional meanings for "in" operator and ability to customize implementation

2019-10-14 Thread Steven D'Aprano
On Mon, Oct 14, 2019 at 07:53:07PM +1100, Chris Angelico wrote: > On Mon, Oct 14, 2019 at 7:04 PM Andrew Barnert wrote: > > If you’re wondering whether integers are something you could define the > > laws of complex algebra over, then no, it isn’t. For example, one of the > > laws is that every

[Python-ideas] Re: Additional meanings for "in" operator and ability to customize implementation

2019-10-14 Thread Steven D'Aprano
On Mon, Oct 14, 2019 at 12:54:13AM -0700, Andrew Barnert via Python-ideas wrote: > On Oct 13, 2019, at 22:54, Chris Angelico wrote: > > > > Mathematically, what's the difference between '1' and '1+0j' (or > > '1+0i')? > > The details depend on what foundations you use, but let’s go with the > m

[Python-ideas] Re: Add Scalar to collections.abc with str, bytes, etc. being both Scalar and Sequence (therefore also Container)

2019-10-14 Thread Steven D'Aprano
On Mon, Oct 14, 2019 at 12:23:43PM +0100, Rhodri James wrote: > In practice I find that's almost never what I want. In the incredibly > rare event that I'm throwing a string at an overly generic interface, I > almost always want it to be treated as a sequence of characters. For what it's worth

[Python-ideas] Re: Add Scalar to collections.abc with str, bytes, etc. being both Scalar and Sequence (therefore also Container)

2019-10-14 Thread Steven D'Aprano
I completely agree that there is a problem to be solved here. Unfortunately I don't think the Scalar ABC is the solution. I'm not sure that there is a generic solution, since different applications will have different ideas of what needs to be drilled down into. E.g. a tuple representing coordi

[Python-ideas] Re: Add Scalar to collections.abc with str, bytes, etc. being both Scalar and Sequence (therefore also Container)

2019-10-14 Thread Andrew Barnert via Python-ideas
On Oct 14, 2019, at 07:15, Steven D'Aprano wrote: > > Speaking of UserString, does anyone know why it isn't registered as a > virtual subclass of str? None of the concrete classes register virtual subclasses, so this would be a unique exception. Also, since 2.3, if you want a subclass of str

[Python-ideas] Re: Set operations with Lists

2019-10-14 Thread Richard Higginbotham
Steve Jorgensen wrote: > What if, instead, there was an OrderedBag class that acts like a > list and supports set operations. > The advantage of this is that any hidden indexing that is used to optimize the > operations could be efficiently created in the object that results from the > set operati

[Python-ideas] Re: Additional meanings for "in" operator and ability to customize implementation

2019-10-14 Thread Andrew Barnert via Python-ideas
On Oct 14, 2019, at 01:53, Chris Angelico wrote: > >> On Mon, Oct 14, 2019 at 7:04 PM Andrew Barnert wrote: >> If you’re wondering whether integers are something you could define the laws >> of complex algebra over, then no, it isn’t. For example, one of the laws is >> that every number beside

[Python-ideas] Re: Additional meanings for "in" operator and ability to customize implementation

2019-10-14 Thread Rhodri James
On 14/10/2019 18:25, Andrew Barnert via Python-ideas wrote: On Oct 14, 2019, at 01:53, Chris Angelico wrote: On Mon, Oct 14, 2019 at 7:04 PM Andrew Barnert wrote: If you’re wondering whether integers are something you could define the laws of complex algebra over, then no, it isn’t. For examp

[Python-ideas] Re: Additional meanings for "in" operator and ability to customize implementation

2019-10-14 Thread Andrew Barnert via Python-ideas
On Oct 14, 2019, at 06:07, Steven D'Aprano wrote: > >> On Mon, Oct 14, 2019 at 12:54:13AM -0700, Andrew Barnert via Python-ideas >> wrote: >>> On Oct 13, 2019, at 22:54, Chris Angelico wrote: >>> >>> Mathematically, what's the difference between '1' and '1+0j' (or >>> '1+0i')? >> >> The detai

[Python-ideas] Re: Add Scalar to collections.abc with str, bytes, etc. being both Scalar and Sequence (therefore also Container)

2019-10-14 Thread Steve Jorgensen
Andrew Barnert wrote: > On Oct 14, 2019, at 07:15, Steven D'Aprano [email protected] wrote: > > Speaking of UserString, does anyone know why it isn't > > registered as a > > virtual subclass of str? > > None of the concrete classes register virtual subclasses, so this would be a > unique excepti

[Python-ideas] Re: Add Scalar to collections.abc with str, bytes, etc. being both Scalar and Sequence (therefore also Container)

2019-10-14 Thread Andrew Barnert via Python-ideas
On Oct 14, 2019, at 13:28, Steve Jorgensen wrote: > > Andrew Barnert wrote: >>> On Oct 14, 2019, at 07:15, Steven D'Aprano [email protected] wrote: >>> Speaking of UserString, does anyone know why it isn't >>> registered as a >>> virtual subclass of str? >>> None of the concrete classes regist

[Python-ideas] Re: Add Scalar to collections.abc with str, bytes, etc. being both Scalar and Sequence (therefore also Container)

2019-10-14 Thread Steve Jorgensen
Andrew Barnert wrote: > On Oct 14, 2019, at 13:28, Steve Jorgensen [email protected] wrote: > > Andrew Barnert wrote: > > On Oct > > 14, 2019, at 07:15, Steven D'Aprano [email protected] wrote: > > Speaking of UserString, does anyone know why it isn't > > registered as a > > virtual subclass of

[Python-ideas] Re: Add Scalar to collections.abc with str, bytes, etc. being both Scalar and Sequence (therefore also Container)

2019-10-14 Thread Steve Jorgensen
Chris Angelico wrote: [snip] > > You're assuming that everyone's definition of Scalar will be the same, > though. I haven't seen that proven. In many cases, the correct check > is "is iterable but is not str". In others, it's "is iterable but is > not (str,bytes)". Some will see an os.stat() result