
On Thu, Nov 03, 2016 at 11:22:45AM +1300, Greg Ewing wrote:
The proposed .? syntax is designed for cases where it's *not* an error for the object to be missing the attribute,
No it is not. That is absolutely not what the syntax means. I'm sorry to single you out Greg, but have you read the PEP? Or even the *title* of the PEP? Or even the subject line of this email thread??? Okay maybe the subject line of this thread isn't too clear (what's Null?). But the PEP is absolutely clear that this is specifically for dealing with None, not arbitrary missing attributes. If you write: obj = [] # oops I meant {} obj?.update(mapping) you will still get an AttributeError, because lists don't have an update method.
*and* the correct action in that situation is to skip whatever you would have done otherwise.
What needs to be decided is whether such use cases are frequent enough to justify special syntax.
I think that the PEP does a good job of demonstrating that use-cases for these None-aware operators are common. -- Steve