MCPcopy
hub / github.com/dask/dask / methodcaller

Class methodcaller

dask/utils.py:1206–1240  ·  view source on GitHub ↗

Return a callable object that calls the given method on its operand. Unlike the builtin `operator.methodcaller`, instances of this class are cached and arguments are passed at call time instead of build time.

Source from the content-addressed store, hash-verified

1204
1205
1206class methodcaller:
1207 """
1208 Return a callable object that calls the given method on its operand.
1209
1210 Unlike the builtin `operator.methodcaller`, instances of this class are
1211 cached and arguments are passed at call time instead of build time.
1212 """
1213
1214 __slots__ = ("method",)
1215 method: str
1216
1217 @property
1218 def func(self) -> str:
1219 # For `funcname` to work
1220 return self.method
1221
1222 def __new__(cls, method: str):
1223 try:
1224 return _method_cache[method]
1225 except KeyError:
1226 self = object.__new__(cls)
1227 self.method = method
1228 _method_cache[method] = self
1229 return self
1230
1231 def __call__(self, __obj, *args, **kwargs):
1232 return getattr(__obj, self.method)(*args, **kwargs)
1233
1234 def __reduce__(self):
1235 return (methodcaller, (self.method,))
1236
1237 def __str__(self):
1238 return f"<{self.__class__.__name__}: {self.method}>"
1239
1240 __repr__ = __str__
1241
1242
1243class itemgetter:

Callers 3

__call__Method · 0.90
test_method_callerFunction · 0.90
__getattr__Method · 0.85

Calls

no outgoing calls

Tested by 1

test_method_callerFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…