MCPcopy
hub / github.com/dask/dask / globalmethod

Function globalmethod

dask/context.py:18–54  ·  view source on GitHub ↗

Allow function to be taken over by globals This modifies a method so that occurrences of it may be taken over by functions registered in the global options. Can be used as a decorator or a function. Parameters ---------- default : callable The default callable to us

(default=None, key=None, falsey=None)

Source from the content-addressed store, hash-verified

16
17
18def globalmethod(default=None, key=None, falsey=None):
19 """Allow function to be taken over by globals
20
21 This modifies a method so that occurrences of it may be taken over by
22 functions registered in the global options. Can be used as a decorator or a
23 function.
24
25 Parameters
26 ----------
27 default : callable
28 The default callable to use.
29 key : str
30 Key under which we register this function in the global parameters
31 falsey : callable, None, optional
32 A function to use if the option is falsey. If not provided, the default
33 is used instead.
34
35 Examples
36 --------
37 >>> import dask
38 >>> class Foo:
39 ... @globalmethod(key='bar', falsey=lambda: 3)
40 ... def bar():
41 ... return 1
42 >>> f = Foo()
43 >>> f.bar()
44 1
45 >>> with dask.config.set(bar=lambda: 2):
46 ... print(f.bar())
47 2
48 >>> with dask.config.set(bar=False):
49 ... print(f.bar())
50 3
51 """
52 if default is None:
53 return partial(globalmethod, key=key, falsey=falsey)
54 return GlobalMethod(default=default, key=key, falsey=falsey)
55
56
57class GlobalMethod:

Callers 8

DelayedClass · 0.90
ItemClass · 0.90
BagClass · 0.90
InheritingClass · 0.90
HLGCollectionClass · 0.90
NotHLGCollectionClass · 0.90
FooClass · 0.90
ArrayClass · 0.90

Calls 1

GlobalMethodClass · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…