The curious thing about PEP 505 as far as I can see is that it
introduces a new piece of syntax -- and for many people (to judge from
the reactions here) a controversial piece of syntax -- to solve what
seems to be a rather specific problem. The use-case that seems most
discussed is unpacking info
Just wanted to note another possibility (most likely to be added to the
"rejected solutions" section).
Add a prefix "!" operator, which will work similarly to the
iterator-unpacking operator "*", but for None.
The expression "[!x]" is equivalent to the expression "[] if x is None else
[x]".
This
Hi All
To start this thread, on 18 July, Steve Dower wrote:
> Possibly this is exactly the wrong time to propose the next big syntax
> change, since we currently have nobody to declare on it, but since we're
> likely to argue for a while anyway it probably can't hurt (and maybe this
> will become
On Wed, Jul 25, 2018 at 07:06:35PM -0400, David Mertz wrote:
> And yes, the problem is that the equivalent is actually:
>
> v = a
> if v is not None: v=a.b
>
> The semantics are simply not the ones that are intuitive to most people
> reading 'v = a?.b'
Tell us more about these "intuitiv
On Thu, Jul 26, 2018 at 1:09 AM, Steven D'Aprano
wrote:
> On Thu, Jul 26, 2018 at 01:02:47AM -0400, Amit Green wrote:
>
> > 3. The problem is way deeper than simply adding '?.' and other
> operators.
> > For real use cases, you also need to say "how far" the an operator can
> > "spread" -- and t
On Thu, Jul 26, 2018 at 01:02:47AM -0400, Amit Green wrote:
> 3. The problem is way deeper than simply adding '?.' and other operators.
> For real use cases, you also need to say "how far" the an operator can
> "spread" -- and this is real hard to solve.
Why do you think that is the case? No oth
On Wed, Jul 25, 2018 at 11:09:35PM -0400, David Mertz wrote:
> Chris Angelica provided a more accurate translation. Do you not see that
> the fact that your *second* try at understanding the actual behavior is
> still wrong suggest that this operator is a HUGE bug magnet?!
Oh what a load of FUD.
On Thu, Jul 26, 2018 at 12:25 AM, Raymond Hettinger <
raymond.hettin...@gmail.com> wrote:
> It probably is the wrong time and probably can hurt (by introducing
> divisiveness when we most need for be focusing on coming together).
>
> This PEP also shares some traits with PEP 572 in that it solves
On Thu, Jul 26, 2018 at 12:17 AM David Mertz wrote:
> On Thu, Jul 26, 2018 at 12:00 AM Nicholas Chammas <
> nicholas.cham...@gmail.com> wrote:
>
>> Forgive me for being slow. I'm missing what's different in semantics
>> between the translation above and Chris's translation below:
>>
>
> You are V
> On Jul 18, 2018, at 10:43 AM, Steve Dower wrote:
>
> Possibly this is exactly the wrong time to propose the next big syntax
> change, since we currently have nobody to declare on it, but since we're
> likely to argue for a while anyway it probably can't hurt (and maybe this
> will become t
On Thu, Jul 26, 2018 at 12:00 AM Nicholas Chammas <
nicholas.cham...@gmail.com> wrote:
> Forgive me for being slow. I'm missing what's different in semantics
> between the translation above and Chris's translation below:
>
You are VERY close now. You have more SPAM, so yours is better:
In [1]:
BTW, even for the "compare to None" issue, the situation in 0.1.1 isn't as
bad as you might think. Definitely a ""
cannot be compared as "is None". But even there, this works:
>>> NullCoalesce(spam).bacon
>>> NullCoalesce(spam).bacon == None
True
>>> NullCoalesce(spam).bacon == 0
False
>>> Null
On Wed, Jul 25, 2018 at 11:09 PM David Mertz wrote:
> On Wed, Jul 25, 2018 at 10:50 PM Nicholas Chammas <
> nicholas.cham...@gmail.com> wrote:
>
>> Indeed. Thanks for the counter-example. I think the correct translation
>> is as follows:
>> food = spam?.eggs?.bacon
>> Becomes:
>> food = N
On Wed, Jul 25, 2018, 11:27 PM Chris Angelico wrote:
> > That's a bug in my proxy too. I'll figure out how to fix it in 0.1.2
> soon.
> > This is early alpha, and the things you're noting are valuable bug
> reports.
> > But none of this is fundamentally unfixable in a library, nor even
> > espec
On Thu, Jul 26, 2018 at 1:19 PM, David Mertz wrote:
> On Wed, Jul 25, 2018 at 11:08 PM Chris Angelico wrote:
>>
>> > Yeah, yeah. I know it's alpha software I wrote two nights ago, and
>> > slightly
>> > patched 5 minutes before that post. You fixed those concerns; I'll
>> > happily
>> > take PR
On Wed, Jul 25, 2018 at 11:08 PM Chris Angelico wrote:
> > Yeah, yeah. I know it's alpha software I wrote two nights ago, and
> slightly
> > patched 5 minutes before that post. You fixed those concerns; I'll
> happily
> > take PRs on fixing them better.
>
> PRs? Nope. I don't think it's possibl
On Wed, Jul 25, 2018 at 10:50 PM Nicholas Chammas <
nicholas.cham...@gmail.com> wrote:
> Indeed. Thanks for the counter-example. I think the correct translation is
> as follows:
> food = spam?.eggs?.bacon
> Becomes:
> food = None
> if spam is not None and spam.eggs is not None:
>
On Thu, Jul 26, 2018 at 12:56 PM, David Mertz wrote:
> On Wed, Jul 25, 2018 at 10:41 PM Chris Angelico wrote:
>>
>> A bit problematic. But after (a) figuring out that your module is
>> named "coalesce" even though I installed "coalescing" AND (b) going
>> and separately installing wrapt, and fina
On Thu, Jul 26, 2018 at 12:45 PM, David Mertz wrote:
> On Wed, Jul 25, 2018 at 10:29 PM Chris Angelico wrote:
>> It is *actually impossible* to
>> perfectly represent short-circuiting semantics in Python!
>
>
> It's INCREDIBLY EASY to represent short-circuiting semantics in Python! What
> on eart
On Wed, Jul 25, 2018 at 10:41 PM Chris Angelico wrote:
> A bit problematic. But after (a) figuring out that your module is
> named "coalesce" even though I installed "coalescing" AND (b) going
> and separately installing wrapt, and finally (c) doing the import that
> you didn't mention, we still
On Wed, Jul 25, 2018 at 10:12 PM David Mertz wrote:
> On Wed, Jul 25, 2018 at 9:47 PM Nicholas Chammas <
> nicholas.cham...@gmail.com> wrote:
>
>> > That is disingenuous, I think. Can this raise an AttributeError?
>>> > spam?.eggs?.bacon
>>> > Of course it can! And this is exactly the patter
On Wed, Jul 25, 2018 at 10:29 PM Chris Angelico wrote:
> food = spam?.eggs?.bacon
>
> can be rewritten as
>
> _tmp = spam
> if _tmp is not None:
> _tmp = _tmp.eggs
> if _tmp is not None:
> _tmp = _tmp.bacon
> food = _tmp
>
Yes, that looks right. Well, you need a `del _tmp` at th
On Thu, Jul 26, 2018 at 12:30 PM, David Mertz wrote:
> Btw. Here's a way of spelling the proposed syntax that gets the semantics
> right:
>
# pip install coalescing
NullCoalesce(spam).eggs.bacon
Let's try it.
rosuav@sikorsky:~$ sudo python3 -m pip install coalescing
Collecting coalesci
Btw. Here's a way of spelling the proposed syntax that gets the semantics
right:
>>> # pip install coalescing
>>> NullCoalesce(spam).eggs.bacon
On Wed, Jul 25, 2018 at 10:14 PM David Mertz wrote:
> So now at least TWO proponents of 505 cannot successfully translate a very
> simple example taken
On Thu, Jul 26, 2018 at 12:14 PM, David Mertz wrote:
> So now at least TWO proponents of 505 cannot successfully translate a very
> simple example taken almost directly from the PEP!
>
> Is that REALLY a good argument for it being helpful, and not being a bug
> magnet?!
>
Okay. I'll give you the
So now at least TWO proponents of 505 cannot successfully translate a very
simple example taken almost directly from the PEP!
Is that REALLY a good argument for it being helpful, and not being a bug
magnet?!
On Wed, Jul 25, 2018 at 9:57 PM Chris Angelico wrote:
> On Thu, Jul 26, 2018 at 11:45 A
On Wed, Jul 25, 2018 at 9:47 PM Nicholas Chammas
wrote:
> > That is disingenuous, I think. Can this raise an AttributeError?
>> > spam?.eggs?.bacon
>> > Of course it can! And this is exactly the pattern used in many examples
>> in
>> > the PEP and the discussion. So the PEP would create a si
On Wed, Jul 25, 2018 at 05:11:08PM -0500, Abe Dillon wrote:
> The problem here is not whether it's explicit. It's about Readability and
> conciseness. Using symbols in place of words almost always harms
> readability in favor of conciseness.
And that is why we prefer COBOL over unreadable Perl-lik
On Thu, Jul 26, 2018 at 11:45 AM, Nicholas Chammas
wrote:
> On Wed, Jul 25, 2018 at 9:20 PM Chris Angelico wrote:
>>
>> On Thu, Jul 26, 2018 at 11:02 AM, David Mertz wrote:
>> > That is disingenuous, I think. Can this raise an AttributeError?
>> >
>> > spam?.eggs?.bacon
>> >
>> > Of course
On Wed, Jul 25, 2018 at 9:20 PM Chris Angelico wrote:
> On Thu, Jul 26, 2018 at 11:02 AM, David Mertz wrote:
> > That is disingenuous, I think. Can this raise an AttributeError?
> >
> > spam?.eggs?.bacon
> >
> > Of course it can! And this is exactly the pattern used in many examples
> in
>
On Thu, Jul 26, 2018 at 11:02 AM, David Mertz wrote:
> That is disingenuous, I think. Can this raise an AttributeError?
>
> spam?.eggs?.bacon
>
> Of course it can! And this is exactly the pattern used in many examples in
> the PEP and the discussion. So the PEP would create a situation where
What if we used ? after the statement beginning?
name ?= person.name
custom_query ?= entity.get_query(context)
# Becomes None if entity is None. Raise an exception if entity is not None and
get_query is None or undefined.
custom_query ??= entity.get_query(context)
# If entity, entity.get_query, e
On Wed, Jul 25, 2018 at 8:00 PM Steven D'Aprano wrote:
> > Every use I've suggested for the magic proxy is similar to:
> > NullCoalesce(cfg).user.profile.food
>
Thanks Steven! Several things you suggest urge some minor improvements to
my slightly-more-than-toy library `coalescing` (
https://p
On Tue, Jul 24, 2018 at 07:02:54AM -0400, David Mertz wrote:
> On Tue, Jul 24, 2018, 5:50 AM Steven D'Aprano wrote:
>
> > But what certainly *is* implicity is David Mertz' suggestion for a
> > magical None-aware proxy:
> >
> > x.attribute
> >
> > The only way to tell whether that was an ordin
On Tue, Jul 24, 2018 at 08:07:36AM -0400, Richard Damon wrote:
> The fact that you changed NullCoalesce into Foo to show lack of
> explicitness seems a straw-man.
I understood Rhodri as making the point that if you don't know what
NullCoalesce means or does, it might as well be called Foo. Ther
On Wed, Jul 25, 2018 at 12:12:40PM -0400, Nicholas Chammas wrote:
> When something is "explicit", as I understand it, that means it does what
> it says on the cover. There is no unstated behavior. The plain meaning of
> `v = a?.b` is that it expands to the longer form (`v = a; if a.b ...`), and
>
David Mertz wrote:
Sorry. From my tablet. "Bug magnets" (it really, really wants to
autocorrect that)
At least it didn't correct it to "butt magnets". :-)
--
Greg
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/l
*sorry, cat hit "send"...
Just reading those examples made me want to cry and go hide in a dark dark
cave and never come out. I'm sure using actual variable names would help a
bit, but not much.
As for the non-english nature of:
value = person.name
I highly disagree with the argument that since
>
> The two statements you wrote are not the same. The first statement will
> error out if person is None.
That's my bad. I was copying off of an erroneous example. Thanks for
correcting me.
The proposed None-aware operators are specifically designed to handle
> variables that may be None.
>
Yes,
On Wed, Jul 25, 2018 at 6:11 PM Abe Dillon wrote:
> The problem here is not whether it's explicit. It's about Readability and
> conciseness. Using symbols in place of words almost always harms
> readability in favor of conciseness.
>
> value = person.name if person.name else person
>
> almost rea
Sorry. From my tablet. "Bug magnets" (it really, really wants to
autocorrect that)
And yes, the problem is that the equivalent is actually:
v = a
if v is not None: v=a.b
The semantics are simply not the ones that are intuitive to most people
reading 'v = a?.b'
On Wed, Jul 25, 2018, 7:01
On Wed, Jul 25, 2018 at 3:11 PM Abe Dillon wrote:
> The problem here is not whether it's explicit. It's about Readability and
> conciseness. Using symbols in place of words almost always harms
> readability in favor of conciseness.
>
> value = person.name if person.name else person
>
> almost rea
>
> The fact that a while bunch have people have commented on this subthread
> while not recognizing that the semantics of the '?.' and the if blocks are
> entirely different suggests the operators are but magnets.
>
Can you explain? What do you mean by "the operators are but magnets"?
The "None
On Wed, Jul 25, 2018 at 6:36 PM David Mertz wrote:
> The fact that a while bunch have people have commented on this subthread
> while not recognizing that the semantics of the '?.' and the if blocks are
> entirely different suggests the operators are but magnets.
>
> On Wed, Jul 25, 2018, 5:17 PM
The fact that a while bunch have people have commented on this subthread
while not recognizing that the semantics of the '?.' and the if blocks are
entirely different suggests the operators are but magnets.
On Wed, Jul 25, 2018, 5:17 PM Nicholas Chammas
wrote:
> On Mon, Jul 23, 2018 at 6:05 PM G
I'm open to any changes or criticism.
```
import atexit
as atexit.register:
# ...do various cleanup tasks...
print('Goodbye')
# is approximately equivalent to =>
import atexit
def _():
# ...do various cleanup tasks...
print('Goodbye')
atexit.register(_)
# flask example
@app.route
The problem here is not whether it's explicit. It's about Readability and
conciseness. Using symbols in place of words almost always harms
readability in favor of conciseness.
value = person.name if person.name else person
almost reads like english (aside from being a weird and totally uncommon
u
On Wed, Jul 25, 2018 at 12:12 PM Nicholas Chammas <
nicholas.cham...@gmail.com> wrote:
> On Mon, Jul 23, 2018 at 6:05 PM Giampaolo Rodola'
> wrote:
>
>> This:
>>
>> v = a?.b
>>
>> ...*implicitly* checks if value is not None [and continues execution].
>> This:
>>
>> v = a
>> if a.b is
On Mon, Jul 23, 2018 at 6:05 PM Giampaolo Rodola'
wrote:
> This:
>
> v = a?.b
>
> ...*implicitly* checks if value is not None [and continues execution].
> This:
>
> v = a
> if a.b is not None:
> v = a.b
>
> ...*explicitly* checks if value is not None and continues execution.
>
Hi All
INTRODUCTION
This is the third and concluding post, where I describe a scheme for
multi-core reference counting garbage collection. The first two posts
are
https://mail.python.org/pipermail/python-ideas/2018-July/052054.html
https://mail.python.org/pipermail/python-ideas/2018-July/052151.h
On Wednesday, July 25, 2018 at 10:33:37 AM UTC+2, Brice Parent wrote:
>
> I think the use case here is not really the simple 'is None' + 'is not
> None'.
>
Sure, that's why I also proposed to manually check a non-too-small samples
of the None-testing occurences found by Guido .
You did it on
Le 25/07/2018 à 08:49, Grégory Lielens a écrit :
BTW, I did (very quickly, so it's rough, my regexps are not really
catching everything) the same or our code base:
"is None"+ "is not None": 5600
AttributeError: 160
3 args getattr: 60
hasattr: 1800
So very similar to your patternexcept for
52 matches
Mail list logo