On 2021-06-21 3:01 p.m., Chris Angelico wrote: > Thanks for clarifying. This doesn't change the problem though - it > just changes where the issue shows up. (BTW, what you're describing is > closer to __getattribute__ than it is to __getattr__, so if you're > proposing this as the semantics, I strongly recommend going with that > name.)
Oh, sorry, thought __getattribute__ was the fallback and __getattr__ the one always called, what with getattr -> __getattr__. But yeah, __getattribute__ then. > > So, here's the question - a clarification of what I asked vaguely up > above. Suppose you have a bunch of these extension methods, and a > large project. How are you going to register the right extension > methods in the right modules within your project? You're binding the > functionality to the module in which the code was compiled, which will > make exec/eval basically unable to use them, and that means you'll > need some way to set them in each module, or to import the setting > from somewhere else. How do you propose doing this? For exec/eval you just pass in the locals: exec(foo, globals(), locals()) because this __getattribute__ is just a local like any other. As for each module, you'd import them. But not quite with "import": import extension_methods # magic module, probably provides an @extend(class_) e.g. @extend(list) import shallow_flatten import deep_flatten __getattribute__ = extension_methods.getattribute( shallow_flatten.flatten, # uses __name__ deepflatten=deep_flatten.flatten, # name override __getattribute__=__getattribute__, # optional, defaults to builtins.getattr ) This would have to be done for each .py that wants to use the extension methods. > > ChrisA > _______________________________________________ > Python-ideas mailing list -- python-ideas@python.org > To unsubscribe send an email to python-ideas-le...@python.org > https://mail.python.org/mailman3/lists/python-ideas.python.org/ > Message archived at > https://mail.python.org/archives/list/python-ideas@python.org/message/3DL46SIS2A7D3W4FNSTH37O6VDJJB2ZP/ > Code of Conduct: http://python.org/psf/codeofconduct/ _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/ROZN62HQYL6X5LCJ7J5DNOC7W3DBGYHF/ Code of Conduct: http://python.org/psf/codeofconduct/