[Python-ideas] Fwd: Define a method or function attributeoutsideof a class with the dot operator
random832 at fastmail.com
Wed Feb 15 00:28:15 EST 2017
On Sun, Feb 12, 2017, at 21:55, Steven D'Aprano wrote:
> But honestly, no. This is not going to happen. .Net VB and C# have
> something like this, as does Lua, and people still write classes the
> ordinary way 99.99% of the time.
The VB/C# thing you are referring to is, I assume, extension methods.
But they're really very different when you look at it. Extension methods
are only used when the namespace containing them has been imported, and
are based on the static type of the object they are being called on.
They also have no access to the object's private members.
Python doesn't have static types and doesn't have private members, and
using this would make a real modification to the type the method is
being added to rather than relying on namespaces being imported, so
there would be fewer barriers to "use this for everything" than "use
extension methods for everything in C#".
More information about the Python-ideas