def _mapfuns(d1, d2):
    """
    Given two dicts, d1 (k1 -> v1) and d2 (k2 -> v2), returns a dict which has
    the mapping (k1 -> k2) such that _name(k1) == _name(k2).
    """
    def _name(fn):
        """
        Strips the line number at the end if any.
        Eg. 'foo.py:23' -> 'foo.py', 'foo:bar.py' -> 'foo:bar.py' etc.
        """
        parts = fn.rsplit(':', 1)
        try:
            int(parts[1])
            return parts[0]
        except Exception:
            return fn

    m1 = [(_name(f), f) for f in d1]
    m2 = dict([(_name(f), f) for f in d2])
    return dict([(v, m2[k]) for k, v in m1 if k in m2])