[Python-ideas] Fwd: Define a method or function attributeoutsideof a class with the dot operator
Paul Moore
p.f.moore at gmail.com
Sun Feb 12 06:38:46 EST 2017
On 12 February 2017 at 04:37, Steven D'Aprano <steve at pearwood.info> wrote:
>> Making a dedicated syntax or decorator for patching is saying that we
>> (the language) think you should do it.
>
> We already have that syntax:
>
> anything.name = thing
And the point here is that we don't need to extend def, because we
already have that syntax. Adding new syntax for something that we can
already do is generally accepted when the "thing we can already do" is
deemed sufficiently important that it's worth making it a language
feature in its own right. Decorators are a prime example of this -
before the decorator syntax was added, decorating functions was just
something that people occasionally did, but it wasn't a specific
"concept".
I'd argue that method injection (to use your phrase) isn't
sufficiently important to warrant promotion to language syntax.
I will say, though, that you're right that we've over-reacted a bit to
the monkeypatching use case. Although maybe that's because no-one can
think of many *other* use cases that they'd need the new syntax for
:-)
Paul
More information about the Python-ideas
mailing list