[Python-ideas] Re: `__lcontains__` for letting the other class determine container membership when `__contains__` fails

2019-11-12 Thread Guido van Rossum
Note that __lcontains__ (if it exists) would be called first, at least for different types. So maybe it would be easier than you think. But I still think it’s not needed. On Tue, Nov 12, 2019 at 9:04 PM Andrew Barnert via Python-ideas < python-ideas@python.org> wrote: > On Nov 12, 2019, at

[Python-ideas] Re: `__lcontains__` for letting the other class determine container membership when `__contains__` fails

2019-11-12 Thread Andrew Barnert via Python-ideas
On Nov 12, 2019, at 17:00, Samuel Muldoon wrote: > > Currently, the `in` operator (also known as `__contains__`) always uses the > rightmost argument's implementation. > > For example, > >>status = obj in "xylophone" > > Is similar to: > > status = "xylophone".__contains__( obj ) >

[Python-ideas] Re: `__lcontains__` for letting the other class determine container membership when `__contains__` fails

2019-11-12 Thread Guido van Rossum
Hm... with only a little bit of cooperation of the container class (e.g. xylophone), you could implement this yourself: class xylophone: def __contains__(self, item): if hasattr(item, '__lcontains__'): return item.__lcontains__(self) return False On Tue, Nov 12,

[Python-ideas] `__lcontains__` for letting the other class determine container membership when `__contains__` fails

2019-11-12 Thread Samuel Muldoon
*Currently, the `in` operator (also known as `__contains__`) always uses the rightmost argument's implementation.* *For example,* > * status = obj in "xylophone" * > *Is similar to:* *status = "xylophone".__contains__( obj )* *The current implementation of `__contains__` is similar

[Python-ideas] Re: Python should take a lesson from APL: Walrus operator not needed

2019-11-12 Thread David Mertz
Yeah. Maybe I should replace regex ' *:=' rather than just ':='. That's easy enough with the plugin On Tue, Nov 12, 2019, 12:12 PM Mike Miller wrote: > > On 2019-11-11 16:13, David Mertz wrote: > > I implemented this discussed arrow operator in vim with conceal plugin. > This is > > an example

[Python-ideas] Re: Suggest having a mechanism to distinguish import sources

2019-11-12 Thread Eric V. Smith
*/PEP 328 doesn’t seem to mention any of the names detailed below./* I strongly advise reading PEPs as documentation once their work has landed. At that point they are mostly historical documents and will not be kept up to date going forward. IOW do not read any import-related PEPs for

[Python-ideas] Re: Suggest having a mechanism to distinguish import sources

2019-11-12 Thread Brett Cannon
On Fri, Nov 8, 2019 at 11:07 AM Ricky Teachey wrote: > > >> __import__ already has a 'level' argument. >> > > doh! maybe "context" is better, then. > > >> Not without frame inspection to know what import statements are in the >> context manager's block. >> >> > I don't doubt you know what you're

[Python-ideas] Re: Suggest having a mechanism to distinguish import sources

2019-11-12 Thread Brett Cannon
On Sat, Nov 9, 2019 at 10:57 AM Steve Barnes wrote: > > > > > *From:* Brett Cannon > *Sent:* 08 November 2019 18:10 > *To:* Ricky Teachey > *Cc:* Dan Sommers <2qdxy4rzwzuui...@potatochowder.com>; python-ideas < > python-ideas@python.org> > *Subject:* [Python-ideas] Re: Suggest having a

[Python-ideas] Re: Python should take a lesson from APL: Walrus operator not needed

2019-11-12 Thread Mike Miller
On 2019-11-11 16:13, David Mertz wrote: I implemented this discussed arrow operator in vim with conceal plugin.  This is an example given in PEP 572.  It looks perfectly fine.  It also does not require ANY change to Python-the-language.  It just means that I can type ':' followed by '=' to

[Python-ideas] Re: Python should take a lesson from APL: Walrus operator not needed

2019-11-12 Thread Marko Ristin-Kaufmann
Hi, > I mean, as shown in this example and a previous one I posted a screenshot > of, I think it's cute and geeky to use a few math symbols in the same way > in my editor. I've been doing that for a few years, and it never got > beyond "slightly cute." > I would second this. I find it