
On Tue, Jul 24, 2018, 5:50 AM Steven D'Aprano <steve@pearwood.info> 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 ordinary attribute lookup or a none-aware lookup would be to carefully inspect x and find out whether it was an instance of the None-aware proxy class or not.
Every use I've suggested for the magic proxy is similar to: NullCoalesce(cfg).user.profile.food Yes, the class is magic. That much more so in the library I published last night that utilizes wrapt.ObjectProxy. But it's also pretty explicit in that an actual *word* announces that funny stuff is going to happen on the same line. Of course the this could be abused with: cfg = NoneCoalesce(cfg) ... 1000 lines ... do_something(cfg) But then, I could also write a property that actually started a computation of the millionth digit of pi while launching a DDoS attack on python.org when a user accessed 'x.attribute'. NoneCoalesce or GreedyAccess are magic, but in their intended use, they are as little magical as possible to deal with messy nested data.