On Wed, Jun 23, 2021 at 8:30 AM Soni L. email@example.com wrote:
On 2021-06-22 5:54 p.m., Chris Angelico wrote:
On Wed, Jun 23, 2021 at 6:41 AM Soni L. firstname.lastname@example.org wrote:
It would have local scope, similar to uh... locals. Y'know how locals are just sugar for locals()['foo'] and stuff? Yeah.
Not really, no, they're not. :) The dictionary returned by locals() isn't actually an implementation detail of local name lookups.
It's... part of the language. Not an implementation detail. The dictionary returned by locals() is an inherent part of local name lookups, isn't it?
No, it's not. Most definitely not.
Have you put any thought into how you would deal with the problem of recursive __dot__ calls?
Let it recurse!
Globals and locals don't go through __dot__, so you can just... use them. In particular, you can always use getattr(), and probably should. Or even set __dot__ to getattr inside it, like so:
def __dot__(left, right): __dot__ = getattr foo.bar # same as getattr(foo, "bar") because we set (local) __dot__ to getattr above
I can't actually pin down what I'm averse to here, but it gives me a really REALLY bad feeling. You're expecting every attribute lookup to now look for a local or global name __dot__ (or, presumably, a nonlocal, class, or builtin), and do whatever that does. That seems like a really effective foot-gun.
Have you actually tried designing this into a larger project to see what problems you run into, or is this something you've only considered at this trivial level?