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
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
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:
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
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:
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
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
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
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
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
> 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
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
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
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
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
> 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
>
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
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):
>
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
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
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
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
> 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
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
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
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
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
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
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.
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
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
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
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
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
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
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:
>
>
>
>
> 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
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
38 matches
Mail list logo