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

Chris Angelico rosuav at gmail.com
Wed Jul 25 21:20:26 EDT 2018


On Thu, Jul 26, 2018 at 11:02 AM, David Mertz <mertz at gnosis.cx> 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 code
> will raise AttributeError in a slightly—and subtly—different set of
> circumstances than plain attribute access will.

I don't understand. If it were to raise AttributeError, it would be
because spam (or spam.eggs) isn't None, but doesn't have an attribute
eggs (or bacon). Exactly the same as regular attribute access. How is
it slightly different? Have I missed something?

ChrisA


More information about the Python-ideas mailing list