[web2py-dev] pydal.helpers.methods.merge_tablemaps()

46 views
Skip to first unread message

Richard

unread,
Feb 28, 2018, 1:14:55 PM2/28/18
to web2py-developers
Hello,

There is another ticket which seems related to this function : https://github.com/web2py/pydal/issues/518

The issue with CROSS JOIN :

I submit a PR to fix #521, but could it make more sens to do the following :

def merge_tablemaps(*maplist):
    """Merge arguments into a single dict, check for name collisions.
    Arguments may be modified in the process."""
    maplist = list(maplist)
    for i, item in enumerate(maplist):
        if isinstance(item, dict):
            maplist[i] = dict(**item)
    ret = maplist[0]
    for item in maplist[1:]:
        if len(ret) > len(item):
            big, small = ret, item
        else:
            big, small = item, ret
        # Check for name collisions
        for key, val in small.items():
            if big.get(key, val) is not val:
                raise ValueError('Name conflict in table list: %s' % key)
        # Merge
        big.update(small)
        ret = big
    return ret

It's not full elegant but it would avoid taking care of issues that could occurs over mutable dict passed variables...

Richard

Richard Vézina

unread,
Mar 1, 2018, 12:39:24 PM3/1/18
to web2py-d...@googlegroups.com
UP

Please also have look here : https://github.com/web2py/pydal/issues/518

Richard

--
-- mail from:GoogleGroups "web2py-developers" mailing list
make speech: web2py-developers@googlegroups.com
unsubscribe: web2py-developers+unsubscribe@googlegroups.com
details : http://groups.google.com/group/web2py-developers
the project: http://code.google.com/p/web2py/
official : http://www.web2py.com/
---
You received this message because you are subscribed to the Google Groups "web2py-developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py-developers+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages