def suppress_message(linter, checker_method, message_id_or_symbol, test_func):
    """
    This wrapper allows the suppression of a message if the supplied test function
    returns True. It is useful to prevent one particular message from being raised
    in one particular case, while leaving the rest of the messages intact.
    """
    # At some point, pylint started preferring message symbols to message IDs. However this is not done
    # consistently or uniformly - occasionally there are some message IDs with no matching symbols.
    # We try to work around this here by suppressing both the ID and the symbol, if we can find it.
    # This also gives us compatability with a broader range of pylint versions.

    # Similarly, a commit between version 1.2 and 1.3 changed where the messages are stored - see:
    # https://bitbucket.org/logilab/pylint/commits/0b67f42799bed08aebb47babdc9fb0e761efc4ff#chg-reporters/__init__.py
    # Therefore here, we try the new attribute name, and fall back to the old version for
    # compatability with <=1.2 and >=1.3
    msgs_store = getattr(linter, 'msgs_store', linter)

    def get_message_definitions(message_id_or_symbol):
        if hasattr(msgs_store, 'check_message_id'):
            return [msgs_store.check_message_id(message_id_or_symbol)]
        # pylint 2.0 renamed check_message_id to get_message_definition in:
        # https://github.com/PyCQA/pylint/commit/5ccbf9eaa54c0c302c9180bdfb745566c16e416d
        elif hasattr(msgs_store, 'get_message_definition'):
            return [msgs_store.get_message_definition(message_id_or_symbol)]
        # pylint 2.3.0 renamed get_message_definition to get_message_definitions in:
        # https://github.com/PyCQA/pylint/commit/da67a9da682e51844fbc674229ff6619eb9c816a
        elif hasattr(msgs_store, 'get_message_definitions'):
            return msgs_store.get_message_definitions(message_id_or_symbol)
        else:
            raise ValueError('pylint.utils.MessagesStore does not have a get_message_definition(s) method')

    try:
        pylint_messages = get_message_definitions(message_id_or_symbol)
        symbols = [symbol
                   for pylint_message in pylint_messages
                   for symbol in (pylint_message.msgid, pylint_message.symbol)
                   if symbol is not None]
    except UnknownMessage:
        # This can happen due to mismatches of pylint versions and plugin expectations of available messages
        symbols = [message_id_or_symbol]

    def do_suppress(chain, node):
        with Suppress(linter) as s:
            if test_func(node):
                s.suppress(*symbols)
            chain()
    augment_visit(linter, checker_method, do_suppress)
def suppress_message ( linter , checker_method , message_id_or_symbol , test_func ) : msgs_store = getattr ( linter , 'msgs_store' , linter ) def get_message_definitions ( message_id_or_symbol ) : if hasattr ( msgs_store , 'check_message_id' ) : return [ msgs_store . check_message_id ( message_id_or_symbol ) ] elif hasattr ( msgs_store , 'get_message_definition' ) : return [ msgs_store . get_message_definition ( message_id_or_symbol ) ] elif hasattr ( msgs_store , 'get_message_definitions' ) : return msgs_store . get_message_definitions ( message_id_or_symbol ) else : raise ValueError ( 'pylint.utils.MessagesStore does not have a get_message_definition(s) method' ) try : pylint_messages = get_message_definitions ( message_id_or_symbol ) symbols = [ symbol for pylint_message in pylint_messages for symbol in ( pylint_message . msgid , pylint_message . symbol ) if symbol is not None ] except UnknownMessage : symbols = [ message_id_or_symbol ] def do_suppress ( chain , node ) : with Suppress ( linter ) as s : if test_func ( node ) : s . suppress ( * symbols ) chain ( ) augment_visit ( linter , checker_method , do_suppress )
This wrapper allows the suppression of a message if the supplied test function
    returns True. It is useful to prevent one particular message from being raised
    in one particular case, while leaving the rest of the messages intact.