Re: [Python-ideas] PEP 505: None-aware operators: operators ?= and ?? and OR

2018-08-02 Thread Alexandre Brault
On 2018-08-02 7:01 PM, Eric Fahlgren wrote: On Thu, Aug 2, 2018 at 3:39 PM MRAB > wrote: In the relevant code, is policy.mangle_from_ ever None? That's impossible to know, since the initializer where this code originally appears puts no constraints on

Re: [Python-ideas] With expressions

2018-08-02 Thread Steven D'Aprano
On Thu, Aug 02, 2018 at 03:13:25PM +0200, Robert Vanden Eynde wrote: > This brings the discussion of variable assignement in Expression. Functional > programming community seems to be more interested in python. I'm not sure what you mean there. Your English grammar is just slightly off, enough

Re: [Python-ideas] PEP 505: None-aware operators: operators ?= and ?? and OR

2018-08-02 Thread Steven D'Aprano
On Thu, Aug 02, 2018 at 06:50:47PM +0200, Pål Grønås Drange wrote: > > Reads the same out loud despite being a different operator. > > How are `??`, `.?`, and the others pronounced? Did you read the PEP? It answers that question. https://www.python.org/dev/peps/pep-0505/#reading-expressions

Re: [Python-ideas] PEP 505: None-aware operators: operators ?= and ?? and OR

2018-08-02 Thread Eric Fahlgren
On Thu, Aug 2, 2018 at 3:39 PM MRAB wrote: > In the relevant code, is policy.mangle_from_ ever None? > That's impossible to know, since the initializer where this code originally appears puts no constraints on the value of 'policy', it's just assumed to have a 'mangle_from_' member... I would

Re: [Python-ideas] PEP 505: None-aware operators: operators ?= and ?? and OR

2018-08-02 Thread MRAB
On 2018-08-02 22:49, Eric Fahlgren wrote: On Thu, Aug 2, 2018 at 1:22 PM MRAB > wrote: > policy?.mangle_from_ ?? True > True (??? since lhs is None?) > No, it's not 'policy.mangle_from_' that could be None, it's 'policy' that could be

Re: [Python-ideas] PEP 505: None-aware operators: operators ?= and ?? and OR

2018-08-02 Thread Eric Fahlgren
On Thu, Aug 2, 2018 at 1:22 PM MRAB wrote: > > policy?.mangle_from_ ?? True > > True (??? since lhs is None?) > > > No, it's not 'policy.mangle_from_' that could be None, it's 'policy' > that could be None (i.e. there's no policy). > In my example, there is a policy, and the value of

Re: [Python-ideas] PEP 505: None-aware operators: operators ?= and ?? and OR

2018-08-02 Thread MRAB
On 2018-08-02 20:03, Eric Fahlgren wrote: From the PEP: > From email/generator.py (and importantly note that there is no way to substitute or for ?? in this situation): > mangle_from_ = True if policy is None else policy.mangle_from_ > After updating: > mangle_from_ =

Re: [Python-ideas] With expressions

2018-08-02 Thread Terry Reedy
On 8/2/2018 7:53 AM, Thomas Nyberg via Python-ideas wrote: On 08/02/2018 12:43 PM, Paul Moore wrote: But if someone wanted to raise a doc bug suggesting that we mention this, I'm not going to bother objecting... Paul I opened a bug here: https://bugs.python.org/issue34319 We can see

Re: [Python-ideas] PEP 505: None-aware operators: operators ?= and ?? and OR

2018-08-02 Thread Jonathan Fine
Hi Eric [Steve Dower: Eric seems to have found a bug in the PEP. Where to report?] You quoted, from PEP 505, Before > mangle_from_ = True if policy is None else policy.mangle_from_ After > mangle_from_ = policy?.mangle_from_ ?? True You then remarked > I cannot see how these are equivalent I

Re: [Python-ideas] PEP 505: None-aware operators: operators ?= and ?? and OR

2018-08-02 Thread Eric Fahlgren
>From the PEP: > >From email/generator.py (and importantly note that there is no way to substitute or for ?? in this situation): > mangle_from_ = True if policy is None else policy.mangle_from_ > After updating: > mangle_from_ = policy?.mangle_from_ ?? True I cannot see how these are equivalent,

Re: [Python-ideas] PEP 505: None-aware operators: operators ?= and ?? and OR

2018-08-02 Thread David Foster
RE none-aware operators in general: +1 overall for the latest version of PEP 505 and the utility of ?? in particular. There are several places in my code that could be simplified with ??. find-pep505.py on my current Django-oriented codebase gives: Total None-coalescing `if` blocks:

Re: [Python-ideas] Change repr of collections.OrderedDict to be more dict-like

2018-08-02 Thread Serhiy Storchaka
27.07.18 16:29, Chris Angelico пише: Ah, fair point. Interestingly, the same problem hits repr(dict(od)), which I would have thought a reliable solution here. The simplest way that I've found is: dict(od.items()) {'b': 2, 'a': 1} That seems very odd. Iterating over the OD produces its keys

Re: [Python-ideas] With expressions

2018-08-02 Thread Robert Vanden Eynde
This brings the discussion of variable assignement in Expression. Functional programming community seems to be more interested in python. lines = (f.readlines() with open('hello') as f) digit = (int('hello') except ValueError: 5) value = (x+y**2 where x,y = (2,4)) values = [x+y**2 for x in

Re: [Python-ideas] With expressions

2018-08-02 Thread Cody Piersall
On Thu, Aug 2, 2018 at 5:24 AM Thomas Nyberg via Python-ideas wrote: > > Is it true that Path('file').read_text() closes the file after the read? A quick look at the source confirms that the file is closed: https://github.com/python/cpython/blob/master/Lib/pathlib.py#L1174 The docstring is

Re: [Python-ideas] With expressions

2018-08-02 Thread Steven D'Aprano
On Thu, Aug 02, 2018 at 11:35:11AM +0200, Ken Hilton wrote: > Where this would benefit: I think the major use case is `f.read() with > open('file') as f`. [...] > Therefore `f.read() with open('file') as f`, I think, would be much > welcomed as the best way to read a file in an expression.

Re: [Python-ideas] With expressions

2018-08-02 Thread Thomas Nyberg via Python-ideas
On 08/02/2018 12:43 PM, Paul Moore wrote: I'm not sure I see why you think it wouldn't - opening and closing the file is a purely internal detail of the function. In any case, you don't get given a file object, so how could anything *other* than the read_text() close the file? So you're

Re: [Python-ideas] With expressions

2018-08-02 Thread Paul Moore
On Thu, 2 Aug 2018 at 11:25, Thomas Nyberg via Python-ideas wrote: > > Is it true that Path('file').read_text() closes the file after the read? > I think that is the sort of functionality that Ken is asking for. > It's not clear to me by your linked documentation that it does. If it > does, maybe

Re: [Python-ideas] With expressions

2018-08-02 Thread Andre Roberge
On Thu, Aug 2, 2018 at 7:24 AM Thomas Nyberg via Python-ideas < python-ideas@python.org> wrote: > Is it true that Path('file').read_text() cl > oses the file after the read? > I think that is the sort of functionality that Ken is asking for. > It's not clear to me by your linked documentation

Re: [Python-ideas] With expressions

2018-08-02 Thread Thomas Nyberg via Python-ideas
Is it true that Path('file').read_text() closes the file after the read? I think that is the sort of functionality that Ken is asking for. It's not clear to me by your linked documentation that it does. If it does, maybe that should be made more clear in that linked documentation? (Of course,

Re: [Python-ideas] With expressions

2018-08-02 Thread Paul Moore
On Thu, 2 Aug 2018 at 10:39, Ken Hilton wrote: > With expressions allow using the enter/exit semantics of the with statement > inside an expression context. Examples: > > contents = f.read() with open('file') as f #the most obvious one > multiplecontents = [f.read() with open(name) as f

[Python-ideas] With expressions

2018-08-02 Thread Ken Hilton
Hi, I don't know if someone has already suggested this before, but here goes: With expressions allow using the enter/exit semantics of the with statement inside an expression context. Examples: contents = f.read() with open('file') as f #the most obvious one multiplecontents = [f.read()