@staticmethod
def _remove_bdb_context(evalue):
    """Remove exception context from Pdb from the exception.

        E.g. "AttributeError: 'Pdb' object has no attribute 'do_foo'",
        when trying to look up commands (bpo-36494).
        """
    removed_bdb_context = evalue
    while removed_bdb_context.__context__:
        ctx = removed_bdb_context.__context__
        if isinstance(ctx, AttributeError
            ) and ctx.__traceback__.tb_frame.f_code.co_name == 'onecmd':
            removed_bdb_context.__context__ = None
            break
        removed_bdb_context = removed_bdb_context.__context__
