
On Tue, Jun 1, 2021 at 9:57 PM Steven D'Aprano <steve@pearwood.info> wrote:
On Thu, May 27, 2021 at 12:33:20PM -0400, Ricky Teachey wrote:
On Thu, May 27, 2021 at 10:25 AM Steven D'Aprano <steve@pearwood.info> wrote:
Okay. Without reading the source code, does this code snippet use the old `__call__` protocol or the new `__decoration_call__` protocol?
@flambé class Banana_Surprise: pass
Invoking @flambé causes:
flambé.__decoration_call__(Banana_Surprise, "Banana_Surprise")
...to be used, if flambé has that method.
Right: you can't tell from the code you are looking at whether flambé is being called as a new or old style decorator. You have to dig into the definition of flambé to work out the meaning of the code.
On the one hand we have the current decorator protocol, where the object flambé is called with a single argument, the class Banana_Surprise.
My understanding is that it would attempt to invoke __detonation_call__ (err, I mean, __decoration_call__, but just think how awesome the other would be) first, and if it can't find it, it falls back on regular __call__. That would parallel how most other things are done - repr falling back to str, iadd falling back to add, etc. That said, I still don't like the idea of decorating a bare name. A magic "assignment target" token that translates into the string form of the thing being assigned to is far more useful and far less magical. ChrisA