Re: [Python-ideas] PEP 505: None-aware operators

2018-07-31 Thread MRAB
On 2018-07-31 20:53, Jonathan Fine wrote: Stephan Houben wrote: Nope, the introduction of the tmp variable changed the semantics. It isn't a "chain" anymore so it breaks shortcutting. I'm confused. Assume 'a' is not defined. With Python's dot (attribute access) we have a.b.c NameError:

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-31 Thread Jonathan Fine
Stephan Houben wrote: > Nope, the introduction of the tmp variable changed the semantics. It isn't a > "chain" anymore so it breaks shortcutting. I'm confused. Assume 'a' is not defined. With Python's dot (attribute access) we have >>> a.b.c NameError: name 'a' is not defined >>> a.(b.c)

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-31 Thread Steven D'Aprano
On Tue, Jul 31, 2018 at 02:14:19PM -0400, David Mertz wrote: > On Tue, Jul 31, 2018, 1:47 PM Steven D'Aprano wrote: > > > Yes it is. Rhodri is correct, although I admit that I hadn't realised > > this point myself until he pointed it out. (That is why until now I've > > been writing examples

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-31 Thread Stephan Houben
Op di 31 jul. 2018 20:49 schreef Jonathan Fine : > David Mertz wrote: > > > `spam?.eggs?.cheese?.aardvark` is NOT redundant for > > `spam?.eggs.cheese.aardvark`. The two expressions simply do different > > things [...] > > I agree, assuming ?. is a binary operator. It isn't. Given this, in

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-31 Thread Jonathan Fine
David Mertz wrote: > `spam?.eggs?.cheese?.aardvark` is NOT redundant for > `spam?.eggs.cheese.aardvark`. The two expressions simply do different > things [...] I agree, assuming ?. is a binary operator. Given this, in Python (+ PEP 505) one can write tmp = spam ?. eggs val1 = tmp ?.

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-31 Thread Rhodri James
On 31/07/18 18:46, Steven D'Aprano wrote: n Mon, Jul 30, 2018 at 12:41:20PM -0500, Abe Dillon wrote: [Rhodri James] On 29/07/18 16:12, Abe Dillon wrote: > spam?.eggs.cheese.aardvark # why would you ever do this? If you knew that if you really have something in "spam", your program

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-31 Thread David Mertz
On Tue, Jul 31, 2018, 1:47 PM Steven D'Aprano wrote: > Yes it is. Rhodri is correct, although I admit that I hadn't realised > this point myself until he pointed it out. (That is why until now I've > been writing examples like "spam?.eggs?.cheese?.aardvark" which is > redundant.) > Again, one

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-31 Thread Steven D'Aprano
On Mon, Jul 30, 2018 at 12:41:20PM -0500, Abe Dillon wrote: [Rhodri James] > > On 29/07/18 16:12, Abe Dillon wrote: > > > spam?.eggs.cheese.aardvark # why would you ever do this? > > > > If you knew that if you really have something in "spam", your program > > guarantees it will have an "eggs"

Re: [Python-ideas] Is this PEP-able? "with" statement inside genexps / list comprehensions

2018-07-31 Thread Serhiy Storchaka
31.07.18 00:26, Oscar Benjamin пише: On 30 July 2018 at 20:15, Rudy Matela wrote: Yielding from a with block should be discouraged rather than given special syntax. There is essentially a contradiction between the meaning/purpose of yield (suspend indefinitely) and with (definitely call

Re: [Python-ideas] Is this PEP-able? "with" statement inside genexps / list comprehensions

2018-07-31 Thread Rhodri James
On 30/07/18 20:15, Rudy Matela wrote: Hello, Do you think it would be nice to allow with statements inside genexps or list comprehensions? The functions __enter__ and __exit__ would be automatically called as iterables are traversed. I am thinking of drafting a PEP about this. Examples: I

Re: [Python-ideas] Redefining method

2018-07-31 Thread Jamesie Pic
I like type() a lot, and the attributes dict it takes as argument works with lambda. My use case is just a python module for a framework provides a default instance for some model, and I thought it would be cool to just change a method without going through I'm really bad at defending ideas,