MCPcopy Index your code
hub / github.com/kernc/backtesting.py / patch

Function patch

backtesting/_util.py:34–44  ·  view source on GitHub ↗
(obj, attr, newvalue)

Source from the content-addressed store, hash-verified

32
33@contextmanager
34def patch(obj, attr, newvalue):
35 had_attr = hasattr(obj, attr)
36 orig_value = getattr(obj, attr, None)
37 setattr(obj, attr, newvalue)
38 try:
39 yield
40 finally:
41 if had_attr:
42 setattr(obj, attr, orig_value)
43 else:
44 delattr(obj, attr)
45
46
47def _as_str(value) -> str:

Callers 6

test_resampleMethod · 0.90
test_MultiBacktestMethod · 0.90
test_patchMethod · 0.90
__init__Method · 0.85
_optimize_gridMethod · 0.85
runMethod · 0.85

Calls

no outgoing calls

Tested by 4

test_resampleMethod · 0.72
test_MultiBacktestMethod · 0.72
test_patchMethod · 0.72
_optimize_gridMethod · 0.68