On Wed, May 6, 2020 at 1:44 PM Alex Hall <alex.mojaki@gmail.com> wrote:
I think this looks great, I can't think of anything wrong with it.

Could we put this into the standard library, so that IDEs and linters are programmed to recognise it?

If it does cover the majority of corner cases, I think this is a great thing to consider.

However on the other hand, wouldn't there be an advantage for the user to be able to make adjustments to the arguments before passing them along, and to be able to control WHEN the autoassign action occurs? Isn't this a very common type thing to do?

Using the same example:

class A:
    @autoassign
    def __init__(self, a, b, c=3):
         b = MyEnum(b)

In the example above, self.b is assigned the value of b, not Enum(b). And even if you called-- or gave the option to call-- func(*args, **kwargs) first, autoassign still wouldn't know that you want to modify the supplied parameter value.

It seems to me like it would be more useful to be able to have access to some sort of partial namespace object, containing the objects that were passed to the function, that could then be passed along.... something like this:

class A:
    def __init__(self, a, b, c=3):
        b = MyEnum(b)
        autoassign(A.get_partial_namespace())

The  get_partial_namespace() method would basically be the same as locals(), except: 1. the name bound to the object that called the function is excluded (self) and 2. any other names that were not part of the call of the function are excluded.

---
Ricky.

"I've never met a Kentucky man who wasn't either thinking about going home or actually going home." - Happy Chandler