[issue42646] Add function that supports "applying" methods

2020-12-15 Thread Josh Rosenberg
Josh Rosenberg added the comment: If you're annoyed by having to use two lines, one to copy, one to call the mutating method, you can use the walrus operator: (y := x.copy()).some_method() or: (y := deepcopy(x)).some_method() Does that cover your use case? For the list case, you'd

[issue42646] Add function that supports "applying" methods

2020-12-15 Thread Eric V. Smith
Eric V. Smith added the comment: This seems way too special case for the stdlib, and especially not as a builtin. I've never seen this pattern before. Why is copy so special? I suggest raising this on the python-ideas mailing list if you'd like to get some traction for it. -- nosy:

[issue42646] Add function that supports "applying" methods

2020-12-15 Thread wyz23x2
wyz23x2 added the comment: Edit: applied should be the better name because of reversed(), sorted() etc. and doesn't conflict with Py 2. -- ___ Python tracker ___

[issue42646] Add function that supports "applying" methods

2020-12-15 Thread wyz23x2
New submission from wyz23x2 : Doing this is generally very annoying: y = x.copy() y.some_method() Sometimes x doesn't have copy(), so: from copy import deepcopy y = deepcopy(x) y.some_method() So maybe a function could be added to help. For example: def apply(obj, function, /, args=(),