[Python-ideas] A better (simpler) approach to PEP 505
Steven D'Aprano
steve at pearwood.info
Mon Jul 23 21:08:37 EDT 2018
On Mon, Jul 23, 2018 at 01:55:48PM -0400, David Mertz wrote:
> On Mon, Jul 23, 2018 at 1:28 PM Steven D'Aprano <steve at pearwood.info> wrote:
>
> > There's the first bug right there. foo.bar.blim ought to raise
> > AttributeError, since there is no blim attribute defined on foo.bar.
> >
>
> Note my observation that this is deliberately different semantics. I want
> to solve the underlying need, not simply emulate the less useful semantics
> of PEP 505.
I know that "laziness and hubris" are virtues in a programmer, but the
PEP authors describe use-cases where *testing for None* is precisely the
semantics wanted. What are your use-cases for greedily swallowing
AttributeError?
Before telling the PEP authors that they have misunderstood their own
uses-cases and that their need isn't what they thought (coalescing None)
but something radically different which they have already explicitly
rejected (suppressing AttributeError), you better have some damn
compelling use-cases.
"Laziness and hubris" are supposed to be virtues in programmers, but
when you insist that people have their own use-cases wrong, and that the
designers of C#, Dart and Swift made a serious mistake introducing this
feature, you ought to back it up with more than just an assertion.
[...]
> It does look like PyMaybe does much of what I'm thinking of. I didn't
> think my toy was the first or best implementation.
Are you aware that the PEP includes pymaybe as a rejected idea?
> > But we aren't entering such a world, at least not in PEP 505. Attribute
> > access can fail.
> > spam.eggs = 42
> > spam?.eggs?.upper
> > is still going to raise AttributeError, because eggs is not None, it is an
> > int, and ints don't have an attribute "upper".
>
> True enough. But it's extremely difficult to imagine a real-world case
> where those particular semantics are actually particularly useful.
You can't imagine why it would be useful to NOT suppress the exception
from a coding error like trying to uppercase an int.
--
Steve
More information about the Python-ideas
mailing list