This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author wyz23x2
Recipients wyz23x2
Date 2020-12-15.13:07:08
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1608037628.46.0.38282222902.issue42646@roundup.psfhosted.org>
In-reply-to
Content
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=(), kwargs={}):
    try:
        new = obj.copy()
    except AttributeError:
        from copy import copy
        new = copy(obj)
    function(new, *args, **kwargs)
    return new
# implement reversed() for list
lis = [1, 2, 3, 4, 5]
arr = apply(lis, list.reverse)
print(arr)  # [5, 4, 3, 2, 1]

apply() maybe isn't the best name because of the builtin apply() in Python 2, but that's EOL. It could be added in the standard library.
History
Date User Action Args
2020-12-15 13:07:08wyz23x2setrecipients: + wyz23x2
2020-12-15 13:07:08wyz23x2setmessageid: <1608037628.46.0.38282222902.issue42646@roundup.psfhosted.org>
2020-12-15 13:07:08wyz23x2linkissue42646 messages
2020-12-15 13:07:08wyz23x2create