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

2019-10-15 Thread Ethan Furman
On 10/14/2019 12:54 AM, 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')? Again, think of Python, but don’t take the analogy too far. You can use `1` almost anywhere you can

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

2019-10-15 Thread Stephen J. Turnbull
Andrew Barnert via Python-ideas writes: > People often think “well, natural numbers aren’t closed over > subtraction, so we’ll just always use integers, and integers aren’t > closed over division so we’ll just always use rationals, …” > assuming that if you keep following that you get to the

[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

[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

[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

[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 >

[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,

[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).

[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 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 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: Additional meanings for "in" operator and ability to customize implementation

2019-10-13 Thread Chris Angelico
On Mon, Oct 14, 2019 at 3:46 PM Andrew Barnert via Python-ideas wrote: > > On Oct 13, 2019, at 18:39, Steven D'Aprano wrote: > > > > Even when the class can be identified as equivalent to > > its set of values, such as for numeric types, there are all sorts of > > complexities that will only

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

2019-10-13 Thread Andrew Barnert via Python-ideas
On Oct 13, 2019, at 18:39, Steven D'Aprano wrote: > > Even when the class can be identified as equivalent to > its set of values, such as for numeric types, there are all sorts of > complexities that will only lead to confusion: > >from numbers import Real >1.0 in Real # okay,

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

2019-10-13 Thread Steven D'Aprano
On Sun, Oct 13, 2019 at 07:15:09PM -, Steve Jorgensen wrote: > …and that leaves only the suggestion that `type.__contains__(self, > other)` could be a synonym for `isinstance(other, self)`. We don't normally think of an instance as being an element contained by its class. We wouldn't say

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

2019-10-13 Thread Steve Jorgensen
This isn't really the same thing as enum since it has nothing to do with numeric values. Per Andrew, however, `__contains__` actually does exactly what I was asking for. ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an

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

2019-10-13 Thread Chris Angelico
On Mon, Oct 14, 2019 at 12:18 AM Steve Jorgensen wrote: > class BrightColorsMeta(type): > def __rin__(self, other): > other.startswith('bright ') > > class BrightColors(metaclass=BrightColorsMeta): pass > > 'red' in BrightColors # -> False > 'bright blue' in

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

2019-10-13 Thread Andrew Barnert via Python-ideas
On Oct 13, 2019, at 02:38, Steve Jorgensen wrote: > > Note that I'm new to this system, so I'm not sure if this will format > correctly or whether I'll be able to edit it afterward to format it properly > if not. Fingers crossed. > > Examples: >import re >from collections import

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

2019-10-13 Thread Random832
On Sun, Oct 13, 2019, at 14:51, David Mertz wrote: > I would not want to overload plain strings' .__contains__() method to > mean "has this substring OR matches this compiled regex." Besides being > on a likely performance path, it's too special. And what about glob > patterns, for example?

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

2019-10-13 Thread Steve Jorgensen
You make an excellent point. I withdraw that from my list of proposed cases. …and that leaves only the suggestion that `type.__contains__(self, other)` could be a synonym for `isinstance(other, self)`. ___ Python-ideas mailing list --

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

2019-10-13 Thread David Mertz
I would not want to overload plain strings' .__contains__() method to mean "has this substring OR matches this compiled regex." Besides being on a likely performance path, it's too special. And what about glob patterns, for example? Those too? But you can wrap your strings in

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

2019-10-13 Thread Steve Jorgensen
I see that __contains__ is not a new thing, so I'm not sure why I didn't notice it. Thanks very much for pointing it out. :) ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org

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

2019-10-13 Thread Antoine Rozo
Hello, For your last example you have the __contains__ special methods. Le dim. 13 oct. 2019 à 15:18, Steve Jorgensen a écrit : > Note that I'm new to this system, so I'm not sure if this will format > correctly or whether I'll be able to edit it afterward to format it > properly if not.