On 2021-06-22 7:38 p.m., Chris Angelico wrote:
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.
Ohh. Fair enough, sorry.
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?
1. It's opt-in. 2. It's designed to be used by a hypothetical extension methods module, but without imposing any design constraints on such module. It could return a named function every time a given name is looked up (a la "bind the first argument" operator), or do dynamic dispatch based on types or ABCs (a la proper extension methods).
In practice, you don't def your own __dot__, but rather use someone else's "__dot__ builder". If you don't wanna deal with it, just don't use __dot__.
It's also useful for the occasional domain-specific language.
ChrisA _______________________________________________ Python-ideas mailing list -- email@example.com To unsubscribe send an email to firstname.lastname@example.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://email@example.com/message/YOPTCI... Code of Conduct: http://python.org/psf/codeofconduct/