On Mon, Jun 6, 2016 at 4:14 PM, Barry Warsaw <barry@python.org> wrote:
On Jun 07, 2016, at 12:53 AM, M.-A. Lemburg wrote:

>This would work as well and indeed reads better, but you'd need
>to have the compiler generate:
>
>      x = obj
>      recordbinding(obj, 'x', 2)
>
>ie. pass in the object, the bound name and the line number
>and recordbinding would then have to decide what to do with the
>parameters.

+1 although I'd bikeshed on the order of the arguments.

>I used the method variant, because a very common use case
>is to let the object know about the name under which it is
>now known to Python. This can be used to eg. define records,
>forms, mappings, etc.

Yep.  So given the above, `recordbinding(obj, 'x', 2)` would of course be free
to delegate to `obj.recordbinding('x', 2)`, but it would be up to the
decorator (and its author), not the compiler to do that delegation.

>I just wonder how we could tell the compiler to special
>case this decorator in a clean way.

That's the rub, but I do think you're on to a good general solution to a
common set of problems.

I think we're on to something here. Maybe. Perhaps.

--
--Guido van Rossum (python.org/~guido)