MCPcopy Create free account
hub / github.com/fabioz/PyDev.Debugger / flag_calls

Function flag_calls

pydev_ipython/matplotlibtools.py:148–173  ·  view source on GitHub ↗

Wrap a function to detect and flag when it gets called. This is a decorator which takes a function and wraps it in a function with a 'called' attribute. wrapper.called is initialized to False. The wrapper.called attribute is set to False right before each call to the wrapped functi

(func)

Source from the content-addressed store, hash-verified

146
147
148def flag_calls(func):
149 """Wrap a function to detect and flag when it gets called.
150
151 This is a decorator which takes a function and wraps it in a function with
152 a 'called' attribute. wrapper.called is initialized to False.
153
154 The wrapper.called attribute is set to False right before each call to the
155 wrapped function, so if the call fails it remains False. After the call
156 completes, wrapper.called is set to True and the output is returned.
157
158 Testing for truth in wrapper.called allows you to determine if a call to
159 func() was attempted and succeeded."""
160
161 # don't wrap twice
162 if hasattr(func, "called"):
163 return func
164
165 def wrapper(*args, **kw):
166 wrapper.called = False
167 out = func(*args, **kw)
168 wrapper.called = True
169 return out
170
171 wrapper.called = False
172 wrapper.__doc__ = func.__doc__
173 return wrapper
174
175
176def activate_pylab():

Callers 2

activate_pylabFunction · 0.85
activate_pyplotFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected