[Python-ideas] more readable "if" for multiple "in" condition

2019-12-31 Thread iman . h . a . khamse
Hi I think the following syntax's: if foo in foobar or bar in foobar or baz in foobar: pass if foo in foobar and bar in foobar and baz in foobar: pass can be more readable and shorter if written as: if foo or bar or baz in foobar: pass if foo and bar and baz in foobar: pass mayb

[Python-ideas] Re: more readable "if" for multiple "in" condition

2019-12-31 Thread Chris Angelico
On Wed, Jan 1, 2020 at 12:50 AM wrote: > > Hi > I think the following syntax's: > > if foo in foobar or bar in foobar or baz in foobar: > pass > if foo in foobar and bar in foobar and baz in foobar: > pass > > can be more readable and shorter if written as: > > if foo or bar or baz in foob

[Python-ideas] Re: more readable "if" for multiple "in" condition

2019-12-31 Thread Serhiy Storchaka
31.12.19 08:20, [email protected] пише: Hi I think the following syntax's: if foo in foobar or bar in foobar or baz in foobar: pass if foo in foobar and bar in foobar and baz in foobar: pass can be more readable and shorter if written as: if foo or bar or baz in foobar:

[Python-ideas] Re: more readable "if" for multiple "in" condition

2019-12-31 Thread 永田大和
I can understand current way is little redundancy. But making new Keyword OR, AND or something like that is not kind to beginners. I don't think this proposal follows the zen of Python. However, I think what you want to say is nice. So, I propose this way. if (1, 2, 3) or in [1, 4, 5]: code

[Python-ideas] Re: more readable "if" for multiple "in" condition

2019-12-31 Thread Richard Damon
On 12/31/19 1:20 AM, [email protected] wrote: Hi I think the following syntax's: if foo in foobar or bar in foobar or baz in foobar: pass if foo in foobar and bar in foobar and baz in foobar: pass can be more readable and shorter if written as: if foo or bar or baz in foobar:

[Python-ideas] Re: more readable "if" for multiple "in" condition

2019-12-31 Thread Jonathan Crall
For what its worth, I find the proposed syntax confusing and difficult to read. Conceptually it makes sense, but using existing set operations seems like a far more readable way to handle this case. On Tue, Dec 31, 2019 at 11:03 AM Richard Damon wrote: > On 12/31/19 1:20 AM, iman.h.a.kha...@gmai

[Python-ideas] Allow metaclass to override __subclasscheck__ for metaclass relations

2019-12-31 Thread Soni L.
I would like this code to work, but currently python ignores __subclasscheck__ in many places where it checks for subclasses: class MM(type):     def __subclasscheck__(self, subclass):     return issubclass(subclass, type) class M(type, metaclass=MM):     pass class N(type):     pass c

[Python-ideas] Re: more readable "if" for multiple "in" condition

2019-12-31 Thread Andrew Barnert via Python-ideas
On Dec 31, 2019, at 08:03, Richard Damon wrote: > > IF I were to change the syntax ( which I don't propose), I believe the > construct like foo or bar or baz in foobar to give you issues parsing. An > alternative which is, in my opinion, more readable would be if any(foo, bar, > baz) in foobar

[Python-ideas] Re: more readable "if" for multiple "in" condition

2019-12-31 Thread David Mertz
I completely agree. All the variations suggested are unreadable mish-mash. Set intersection exists already and it's completely clear. On Tue, Dec 31, 2019, 12:05 PM Jonathan Crall wrote: > For what its worth, I find the proposed syntax confusing and difficult to > read. Conceptually it makes sen

[Python-ideas] Re: more readable "if" for multiple "in" condition

2019-12-31 Thread Richard Damon
On 12/31/19 12:49 PM, Andrew Barnert via Python-ideas wrote: On Dec 31, 2019, at 08:03, Richard Damon wrote: IF I were to change the syntax ( which I don't propose), I believe the construct like foo or bar or baz in foobar to give you issues parsing. An alternative which is, in my opinion, mo

[Python-ideas] Re: more readable "if" for multiple "in" condition

2019-12-31 Thread Andrew Barnert via Python-ideas
> On Dec 31, 2019, at 07:30, 永田大和 wrote: > > However, I think what you want to say is nice. > So, I propose this way. > > if (1, 2, 3) or in [1, 4, 5]: > code Even knowing what you want this to mean, I have a very hard time reading it as meaning that. To me, if `a or in b` means anything, it

[Python-ideas] Re: Allow metaclass to override __subclasscheck__ for metaclass relations

2019-12-31 Thread Anders Hovmöller
You forgot something in that example I think because it doesn't actually do anything that can "not work". > On 31 Dec 2019, at 18:41, Soni L. wrote: > > I would like this code to work, but currently python ignores > __subclasscheck__ in many places where it checks for subclasses: > > class

[Python-ideas] Re: Allow metaclass to override __subclasscheck__ for metaclass relations

2019-12-31 Thread Soni L.
Okay. How about this then: class MM(type):     def __subclasscheck__(self, subclass):     return issubclass(subclass, type) class M(type, metaclass=MM):     pass class N(type):     pass class C(metaclass=M):     pass class D(metaclass=N):     pass class E(C, D, metaclass=N):     pas

[Python-ideas] Re: Allow metaclass to override __subclasscheck__ for metaclass relations

2019-12-31 Thread Anders Hovmöller
Tried that. Got: TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases You should probably try the example you're trying to post before posting it. > On 31 Dec 2019, at 19:19, Soni L. wrote: > > Okay. How about th

[Python-ideas] Re: Allow metaclass to override __subclasscheck__ for metaclass relations

2019-12-31 Thread Soni L.
Yes. That's my point. I don't like that error. On 2019-12-31 3:23 p.m., Anders Hovmöller wrote: Tried that. Got: TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases You should probably try the example you're tryin

[Python-ideas] Re: more readable "if" for multiple "in" condition

2019-12-31 Thread Andrew Barnert via Python-ideas
> On Dec 31, 2019, at 05:50, [email protected] wrote: > > if foo or bar or baz in foobar: > pass > if foo and bar and baz in foobar: > pass > > maybe for "is" instead of: > > if foobar is foo or foobar is bar or foobar is baz: > pass > > if foobar is foo or bar or baz: > pass >

[Python-ideas] Re: Allow metaclass to override __subclasscheck__ for metaclass relations

2019-12-31 Thread Andrew Barnert via Python-ideas
On Dec 31, 2019, at 09:43, Soni L. wrote: > > I would like this code to work, but currently python ignores > __subclasscheck__ in many places where it checks for subclasses: > > class MM(type): > def __subclasscheck__(self, subclass): > return issubclass(subclass, type) > > > cla

[Python-ideas] Re: Allow metaclass to override __subclasscheck__ for metaclass relations

2019-12-31 Thread Soni L.
On 2019-12-31 3:56 p.m., Andrew Barnert wrote: On Dec 31, 2019, at 09:43, Soni L. wrote: > > I would like this code to work, but currently python ignores __subclasscheck__ in many places where it checks for subclasses: > > class MM(type): > def __subclasscheck__(self, subclass): >

[Python-ideas] Re: Allow metaclass to override __subclasscheck__ for metaclass relations

2019-12-31 Thread Andrew Barnert via Python-ideas
On Dec 31, 2019, at 11:02, Soni L. wrote: > > >> On 2019-12-31 3:56 p.m., Andrew Barnert wrote: >> On Dec 31, 2019, at 09:43, Soni L. wrote: >> > > I would like this code to work, but currently python ignores >> > > __subclasscheck__ in many places where it checks for subclasses: >> > > class

[Python-ideas] Re: more readable "if" for multiple "in" condition

2019-12-31 Thread MRAB
On 2019-12-31 17:49, Andrew Barnert via Python-ideas wrote: On Dec 31, 2019, at 08:03, Richard Damon wrote: IF I were to change the syntax ( which I don't propose), I believe the construct like foo or bar or baz in foobar to give you issues parsing. An alternative which is, in my opinion, mo

[Python-ideas] Re: more readable "if" for multiple "in" condition

2019-12-31 Thread Andrew Barnert via Python-ideas
On Dec 31, 2019, at 11:50, MRAB wrote: > > On 2019-12-31 17:49, Andrew Barnert via Python-ideas wrote: >>> On Dec 31, 2019, at 08:03, Richard Damon wrote: >>> IF I were to change the syntax ( which I don't propose), I believe the >>> construct like foo or bar or baz in foobar to give you issue

[Python-ideas] Re: more readable "if" for multiple "in" condition

2019-12-31 Thread MRAB
On 2019-12-31 20:26, Andrew Barnert wrote: On Dec 31, 2019, at 11:50, MRAB wrote: > > On 2019-12-31 17:49, Andrew Barnert via Python-ideas wrote: >>> On Dec 31, 2019, at 08:03, Richard Damon wrote: >>> IF I were to change the syntax ( which I don't propose), I believe the construct like foo

[Python-ideas] Re: more readable "if" for multiple "in" condition

2019-12-31 Thread David Mertz
> if foo OR bar OR baz in foobar: > pass > Someone else noted, and I agreed, that set intersection is already the obvious way to do this. But yes, some things aren't hashable. So in concept you could make a custom type that had some set-like behaviors, and so on. But all of this is crazy work

[Python-ideas] Target-and-expression lists and if-try

2019-12-31 Thread Andrew Barnert via Python-ideas
Every so often, someone suggests that Python should have a pattern matching case statement like Scala, C#, Swift, Haskell, etc. Or they just suggest that “Python needs algebraic data types” but end up concluding that the biggest part Python is missing is not the types themselves, but a practical

[Python-ideas] Re: Target-and-expression lists and if-try

2019-12-31 Thread Andrew Barnert via Python-ideas
To make things a little more concrete (still without actually defining the library or searching for better motivating examples), here’s a slightly rewritten example from the Scala tutorial: def showNotification(notification: Notification) = { notification match { case Ema

[Python-ideas] Re: Target-and-expression lists and if-try

2019-12-31 Thread Soni L.
On 2019-12-31 7:28 p.m., Andrew Barnert via Python-ideas wrote: Every so often, someone suggests that Python should have a pattern matching case statement like Scala, C#, Swift, Haskell, etc. Or they just suggest that “Python needs algebraic data types” but end up concluding that the biggest

[Python-ideas] Re: Target-and-expression lists and if-try

2019-12-31 Thread Andrew Barnert via Python-ideas
On Dec 31, 2019, at 14:58, Soni L. wrote: > > >> On 2019-12-31 7:28 p.m., Andrew Barnert via Python-ideas wrote: >> >> The second is an “if try” statement, which tries an expression and runs the >> body if that doesn’t raise (instead of if it’s truthy), but jumps to the >> next elif/else/stat

[Python-ideas] Re: more readable "if" for multiple "in" condition

2019-12-31 Thread Greg Ewing
if a or b or c is in x: if a and b and c are in x: -- Greg ___ Python-ideas mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message ar

[Python-ideas] Re: Target-and-expression lists and if-try

2019-12-31 Thread Greg Ewing
On 1/01/20 11:28 am, Andrew Barnert via Python-ideas wrote: The first is to extend unpacking assignment to target-or-expression lists. Like this: x, 0, z = vec But it doesn’t bind anything to the second element; instead, it checks if that element is 0, and, if not, raises a ValueError.

[Python-ideas] Re: more readable "if" for multiple "in" condition

2019-12-31 Thread Christopher Barker
I might go with: (a, b, c) orin something And (a, b, c) andin something But really, not needed. -CHB On Tue, Dec 31, 2019 at 3:25 PM Greg Ewing wrote: > if a or b or c is in x: > > if a and b and c are in x: > > -- > Greg > ___ > Python-ideas mail

[Python-ideas] Re: Target-and-expression lists and if-try

2019-12-31 Thread Andrew Barnert via Python-ideas
On Dec 31, 2019, at 15:52, Greg Ewing wrote: > > On 1/01/20 11:28 am, Andrew Barnert via Python-ideas wrote: > >> The first is to extend unpacking assignment to target-or-expression lists. >> Like this: >>x, 0, z = vec >> But >> it doesn’t bind anything to the second element; instead, it c

[Python-ideas] Re: Target-and-expression lists and if-try

2019-12-31 Thread David Mertz
On Tue, Dec 31, 2019 at 8:23 PM Andrew Barnert via Python-ideas < [email protected]> wrote: > > K = 42 > > x, K, z = vec > Yes. I’m surveying the way other languages deal with this to try to figure > out what might fit best for Python. > Some languages use special syntax to mark either value

[Python-ideas] Re: more readable "if" for multiple "in" condition

2019-12-31 Thread Steven D'Aprano
On Tue, Dec 31, 2019 at 05:25:51PM +0200, Serhiy Storchaka wrote: > 31.12.19 08:20, [email protected] пише: [...] > >if foo or bar or baz in foobar: > > pass [...] > >if foobar is foo or bar or baz: > > pass > This looks like an interesting idea for a completely new programming

[Python-ideas] Re: Target-and-expression lists and if-try

2019-12-31 Thread Andrew Barnert via Python-ideas
On Dec 31, 2019, at 17:54, David Mertz wrote: > >  >> On Tue, Dec 31, 2019 at 8:23 PM Andrew Barnert via Python-ideas >> wrote: > >> > K = 42 >> > x, K, z = vec >> Yes. I’m surveying the way other languages deal with this to try to figure >> out what might fit best for Python. >> Some langua

[Python-ideas] Re: Target-and-expression lists and if-try

2019-12-31 Thread Andrew Barnert via Python-ideas
Let me make this bit a little clearer: > On Dec 31, 2019, at 17:54, David Mertz wrote: > > So your syntax gets me maybe 20% of what I'd want to do if we had pattern > matching. I’m not proposing either of these changes in its own, because I don’t have any use for either one on its own. (Or fo

[Python-ideas] Re: Target-and-expression lists and if-try

2019-12-31 Thread Guido van Rossum
There were match proposals in the past — have you looked those up? Maybe they solve your problem without that syntax — or maybe they would benefit from it. On Tue, Dec 31, 2019 at 19:20 Andrew Barnert via Python-ideas < [email protected]> wrote: > Let me make this bit a little clearer: > >

[Python-ideas] Re: Target-and-expression lists and if-try

2019-12-31 Thread David Mertz
> > > class MatchType(type): > def __eq__(self, other): > return self == type(other) > > Or I even want to match: > > type[int], y < 42, z = vec > > Well, I can’t think of a language where you can actually match that way. > That doesn’t necessarily mean we should disallo

[Python-ideas] Re: more readable "if" for multiple "in" condition

2019-12-31 Thread komissar . off . andrey
Maybe then this syntax will be more readable? :)(a, b, c) all in somethingAnd(a, b, c) any in somethingAnd yes, i do not see need for this.PS. Happy New Year!3:56, 1 января 2020 г., Christopher Barker :I might go with:(a, b, c) orin somethingAnd(a, b, c) andin somethingBut really, not needed.-CHBOn