From 61b3aebd3ebc2e874e408e43654f532d7c710ede Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Kl=C3=B6ckner?= Date: Mon, 5 Apr 2021 13:27:52 -0500 Subject: [PATCH] Explain why obj_array_vectorized_n_args can't use partial --- pytools/obj_array.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pytools/obj_array.py b/pytools/obj_array.py index e3b0fa8..9107d7a 100644 --- a/pytools/obj_array.py +++ b/pytools/obj_array.py @@ -214,6 +214,17 @@ def obj_array_vectorize_n_args(f, *args): def obj_array_vectorized_n_args(f): + # Unfortunately, this can't use partial(), as the callable returned by it + # will not be turned into a bound method upon attribute access. + # Only exactly function objects receive this treatment. + # + # Spec link: + # https://docs.python.org/3/reference/datamodel.html#the-standard-type-hierarchy + # (under "Instance Methods", quote as of Py3.9.4) + # > Also notice that this transformation only happens for user-defined functions; + # > other callable objects (and all non-callable objects) are retrieved + # > without transformation. + def wrapper(*args): return obj_array_vectorize_n_args(f, *args) -- GitLab