I've read all the posts in this thread, and am overall at least -0.5 on the
idea. I like methods well enough, but mostly it just seems to invite
confusion versus the equivalent and existing option of importing functions.

I am happy, initially, to stipulate that "some clever technique" is
available to make accessing an extension method/attribute efficient. My
objection isn't that.

Rather, my concern is "spooky action at a distance." It becomes difficult
to know whether my object 'foo' will have the '.do_blaz()' method or not.
Not difficult like no determinate rule could exist, but difficult in the
sense that I'm looking at this one line of code in a thousand line module.
The type() of 'foo' is no longer enough information to know the answer.

That said, one crucial difference is once an extension method is "used" we
are stuck with it for the entire module. In contrast, functions can be both
namespaced and redefined. So I can do:

import alpha, beta
if alpha.do_blaz() == beta.do_blaz(): ...

I can also do this:

from alpha import do_blaz
def myfun():
    from beta import do_blaz
    ...

We get scoping and namespaces that extension method lack.

So perhaps we could add that?

from extensions import do_blaz

with extend(list, do_blaz):
    assert isinstance(foo, list)
    foo.do_blaz()

This would avoid the drawbacks I perceive. On the other hand, it feels like
ain't a fair amount of complexity for negligible actual gain.
_______________________________________________
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/RP6YV736DYMNDETA25IGMPO4HKGG4H3M/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to