Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix recursive call to _substmerge (issue #60) #64

Merged
merged 7 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ SHELL = /bin/bash
PYVERSIONS ?= $(shell py3versions -i)
PYVERSIONSPATHS = $(shell for PV in $(PYVERSIONS); do which $$PV; done)

TESTLOGLEVEL ?= WARN

.PHONY: test examples testinstall all

PYTHONPATH=$(shell pwd)
Expand Down Expand Up @@ -42,7 +44,7 @@ test:
for p in $(PYVERSIONS); do \
echo "python version $$p"; \
for t in test/test_*.py; do \
$$p -t $$t; \
$$p -t $$t -l $(TESTLOGLEVEL); \
RET=$$?; \
if [ $$RET -gt 0 ]; then break 2; fi; \
done; \
Expand Down
18 changes: 9 additions & 9 deletions hiyapyco/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ def _simplemerge(self, a, b):

def _substmerge(self, a, b):
logger.debug('>' * 30)
logger.debug('deepmerge %s and %s' % (a, b,))
logger.debug('substmerge %s and %s' % (a, b,))
# FIXME: make None usage configurable
if b is None:
logger.debug('pass as b is None')
Expand All @@ -352,26 +352,26 @@ def _substmerge(self, a, b):
# subsititues list, don't merge them

if a is None or isinstance(b, primitiveTypes) or isinstance(b, listTypes):
logger.debug('deepmerge: replace a "%s" w/ b "%s"' % (a, b,))
logger.debug('substmerge: replace a "%s" w/ b "%s"' % (a, b,))
a = b

elif isinstance(a, dict):
if isinstance(b, dict):
logger.debug('deepmerge: dict ... "%s" and "%s"' % (a, b,))
logger.debug('substmerge: dict ... "%s" and "%s"' % (a, b,))
for k in b:
if k in a:
logger.debug(
'deepmerge dict: loop for key "%s": "%s" and "%s"' % (k, a[k], b[k],)
'substmerge dict: loop for key "%s": "%s" and "%s"' % (k, a[k], b[k],)
)
a[k] = self._deepmerge(a[k], b[k])
a[k] = self._substmerge(a[k], b[k])
else:
logger.debug('deepmerge dict: set key %s' % k)
logger.debug('substmerge dict: set key %s' % k)
a[k] = b[k]
elif isinstance(b, listTypes):
logger.debug('deepmerge: dict <- list ... "%s" <- "%s"' % (a, b,))
logger.debug('substmerge: dict <- list ... "%s" <- "%s"' % (a, b,))
for bd in b:
if isinstance(bd, dict):
a = self._deepmerge(a, bd)
a = self._substmerge(a, bd)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zerwes The Same change is also needed in line 366 and that should be it.

else:
raise HiYaPyCoImplementationException(
'can not merge element from list of type %s to dict '
Expand All @@ -383,7 +383,7 @@ def _substmerge(self, a, b):
'can not merge %s to %s (@ "%s" try to merge "%s")' %
(type(b), type(a), a, b,)
)
logger.debug('end deepmerge part: return: "%s"' % a)
logger.debug('end substmerge part: return: "%s"' % a)
logger.debug('<' * 30)
return a

Expand Down
4 changes: 2 additions & 2 deletions test/test_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@

t = conf['array']
logger.info('test list val ... %s' % t)
assert t == ['base1', 'base2', 'baseext1', 'baseext2']
assert t == ['baseext1', 'baseext2']

t = conf['hash']
logger.info('test simple dict ... %s' % t)
assert t == {'k1': 'b1', 'k2': 'b2', 'ek1': 'be1', 'ek2': 'be2'}

t = conf['deeplist']
logger.info('test deeplist ... %s' % t)
assert t == [{'d1': {'d1k1': 'v1', 'd1k2': 'v2', 'd1ext': 'vext'}}, {'d2': {'d2k2': 'x2', 'd2k1': 'x1'}}, {'d32': {'a': 'A2A2', 'c': 'CCC', 'b': 'B2'}, 'd31': {'a': 'AAA', 'c': 'C', 'b': 'B'}}, {'dext1': {'d1k1ext': 'v1ext'}}]
assert t == [{'d1': {'d1ext': 'vext'}}, {'dext1': {'d1k1ext': 'v1ext'}}, {'d31': {'a': 'AAA'}, 'd32': {'a': 'A2A2', 'c': 'CCC'}}]

t = conf.get('deepmap')
logger.info('test deepmap ... %s' % t)
Expand Down
Loading