Skip to content

Commit 2d6edbe

Browse files
finish make_mpf_style() bug fix; bump version
1 parent 0b2988d commit 2d6edbe

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/mplfinance/_styles.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ def _valid_make_mpf_style_kwargs():
9696
'rc' : { 'Default' : None,
9797
'Validator' : lambda value: isinstance(value,dict) },
9898

99+
'legacy_rc' : { 'Default' : None, # Just in case someone depended upon old behavior
100+
'Validator' : lambda value: isinstance(value,dict) },
101+
99102
'style_name' : { 'Default' : None,
100103
'Validator' : lambda value: isinstance(value,str) },
101104

@@ -108,6 +111,19 @@ def available_styles():
108111

109112
def make_mpf_style( **kwargs ):
110113
config = _process_kwargs(kwargs, _valid_make_mpf_style_kwargs())
114+
if config['rc'] is not None and config['legacy_rc'] is not None:
115+
raise ValueError('kwargs `rc` and `legacy_rc` may NOT be used together!')
116+
117+
# -----------
118+
# March 2021: Found bug that if caller used `base_mpf_style` and `rc` at
119+
# the same time, then the caller's `rc` will completely replace the `rc`
120+
# of `base_mpf_style`. That was never the intention! Rather it should be
121+
# that the caller's `rc` merely adds to and/or modifies the `rc` of the
122+
# `base_mpf_style`. In order to provide a path to "backwards compatibility"
123+
# for users who may have depended on the bug behavior (callers `rc` replaces
124+
# `rc` of `base_mpf_style`) we provide a new kwarg `legacy_rc` which will
125+
# now behave the way that `rc` used to behave.
126+
# -----------
111127

112128
if config['base_mpf_style'] is not None:
113129
style = _get_mpfstyle(config['base_mpf_style'])
@@ -122,6 +138,9 @@ def make_mpf_style( **kwargs ):
122138
if style['rc'] is None:
123139
style['rc'] = {}
124140
style['rc'].update(rc)
141+
elif config['legacy_rc'] is not None:
142+
config['rc'] = config['legacy_rc']
143+
del config['legacy_rc']
125144
update = [ (k,v) for k,v in config.items() if v is not None ]
126145
style.update(update)
127146
else:

src/mplfinance/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
version_info = (0, 12, 7, 'alpha', 8)
2+
version_info = (0, 12, 7, 'alpha', 9)
33

44
_specifier_ = {'alpha': 'a','beta': 'b','candidate': 'rc','final': ''}
55

0 commit comments

Comments
 (0)