On Wed, May 6, 2020 at 8:08 PM Ricky Teachey <ri...@teachey.org> wrote:
> On Wed, May 6, 2020 at 1:44 PM Alex Hall <alex.moj...@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. > But you could just write `self.b = MyEnum(b)`, and it would overwrite the auto-assigned `self.b = b`. > 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. > This sounds very similar to Steven's parameters() proposal.
_______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/FH5V2AZK6EJQSLGIFAHOOSTZWRUNA322/ Code of Conduct: http://python.org/psf/codeofconduct/