X Tutup

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 vstinner
Recipients Antony.Lee, brett.cannon, hrik2001, mark.dickinson, rhettinger, vstinner
Date 2021-08-30.15:50:45
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1630338645.78.0.265879327189.issue44019@roundup.psfhosted.org>
In-reply-to
Content
Python 2.7 had apply(func, args, kwargs) which called func(*args, **kwargs).
https://docs.python.org/2.7/library/functions.html#apply

There is also functools.partial(func, *args, **kwargs)(*args2, **kwargs2) which calls func(*args, *args2, **kwargs, **kwargs2).
https://docs.python.org/dev/library/functools.html#functools.partial

operator.methodcaller(name, /, *args, **kwargs)(obj) calls getattr(obj, name)(*args, **kwargs).
https://docs.python.org/dev/library/operator.html#operator.methodcaller

I'm not convinced that operator.caller() would be useful to me. Why do you consider that it belongs to the stdlib? It is a common pattern? Did you see in this pattern in the current stdlib?

Can't you easily implement such helper function in a few lines of Python?

operator documentation says: "The operator module exports a set of efficient functions corresponding to the intrinsic operators of Python". I don't see how operator.caller() implements an existing "intrinsic operators of Python".

methodcaller() can be implemented in 4 lines of Python, as shown in its documentation:
---
def methodcaller(name, /, *args, **kwargs):
    def caller(obj):
        return getattr(obj, name)(*args, **kwargs)
    return caller
---
History
Date User Action Args
2021-08-30 15:50:45vstinnersetrecipients: + vstinner, brett.cannon, rhettinger, mark.dickinson, Antony.Lee, hrik2001
2021-08-30 15:50:45vstinnersetmessageid: <1630338645.78.0.265879327189.issue44019@roundup.psfhosted.org>
2021-08-30 15:50:45vstinnerlinkissue44019 messages
2021-08-30 15:50:45vstinnercreate
X Tutup