src/pybel/utils.py
def subdict_matches(target: Mapping, query: Mapping, partial_match: bool = True) -> bool:
    """Check if all the keys in the query dict are in the target dict, and that their values match.

    1. Checks that all keys in the query dict are in the target dict
    2. Matches the values of the keys in the query dict
        a. If the value is a string, then must match exactly
        b. If the value is a set/list/tuple, then will match any of them
        c. If the value is a dict, then recursively check if that subdict matches

    :param target: The dictionary to search
    :param query: A query dict with keys to match
    :param partial_match: Should the query values be used as partial or exact matches? Defaults to :code:`True`.
    :return: if all keys in b are in target_dict and their values match
    """
    for k, v in query.items():
        if k not in target:
            return False
        elif not isinstance(v, (int, str, dict, Iterable)):
            raise ValueError('invalid value: {}'.format(v))
        elif isinstance(v, (int, str)) and target[k] != v:
            return False
        elif isinstance(v, dict):
            if partial_match:
                if not isinstance(target[k], dict):
                    return False
                elif not subdict_matches(target[k], v, partial_match):
                    return False
            elif not partial_match and target[k] != v:
                return False
        elif isinstance(v, Iterable) and target[k] not in v:
            return False

    return True
Check if all the keys in the query dict are in the target dict, and that their values match.

    1. Checks that all keys in the query dict are in the target dict
    2. Matches the values of the keys in the query dict
        a. If the value is a string, then must match exactly
        b. If the value is a set/list/tuple, then will match any of them
        c. If the value is a dict, then recursively check if that subdict matches

    :param target: The dictionary to search
    :param query: A query dict with keys to match
    :param partial_match: Should the query values be used as partial or exact matches? Defaults to :code:`True`.
    :return: if all keys in b are in target_dict and their values match
    
Check if all the keys in the query dict are in the target dict, and that their values match.
1. Checks that all keys in the query dict are in the target dict
2. Matches the values of the keys in the query dict
a. If the value is a string, then must match exactly
b. If the value is a set/list/tuple, then will match any of them
c. If the value is a dict, then recursively check if that subdict matches
Check if all the keys in the query dict are in the target dict and that their values match . 1 . Checks that all keys in the query dict are in the target dict 2 . Matches the values of the keys in the query dict a . If the value is a string then must match exactly b . If the value is a set / list / tuple then will match any of them c . If the value is a dict then recursively check if that subdict matches
def subdict_matches(target: Mapping, query: Mapping, partial_match: bool = True) -> bool:
    for k, v in query.items():
        if k not in target:
            return False
        elif not isinstance(v, (int, str, dict, Iterable)):
            raise ValueError('invalid value: {}'.format(v))
        elif isinstance(v, (int, str)) and target[k] != v:
            return False
        elif isinstance(v, dict):
            if partial_match:
                if not isinstance(target[k], dict):
                    return False
                elif not subdict_matches(target[k], v, partial_match):
                    return False
            elif not partial_match and target[k] != v:
                return False
        elif isinstance(v, Iterable) and target[k] not in v:
            return False
    return True
def subdict_matches ( target : Mapping , query : Mapping , partial_match : bool = True ) -> bool : for k , v in query . items ( ) : if k not in target : return False elif not isinstance ( v , ( int , str , dict , Iterable ) ) : raise ValueError ( 'invalid value: {}' . format ( v ) ) elif isinstance ( v , ( int , str ) ) and target [ k ] != v : return False elif isinstance ( v , dict ) : if partial_match : if not isinstance ( target [ k ] , dict ) : return False elif not subdict_matches ( target [ k ] , v , partial_match ) : return False elif not partial_match and target [ k ] != v : return False elif isinstance ( v , Iterable ) and target [ k ] not in v : return False return True
Check if all the keys in the query dict are in the target dict, and that their values match.
Check if all the keys in the query dict are in the target dict and that their values match .
"""Check if all the keys in the query dict are in the target dict, and that their values match.

    1. Checks that all keys in the query dict are in the target dict
    2. Matches the values of the keys in the query dict
        a. If the value is a string, then must match exactly
        b. If the value is a set/list/tuple, then will match any of them
        c. If the value is a dict, then recursively check if that subdict matches

    :param target: The dictionary to search
    :param query: A query dict with keys to match
    :param partial_match: Should the query values be used as partial or exact matches? Defaults to :code:`True`.
    :return: if all keys in b are in target_dict and their values match
    """
if all keys in b are in target_dict and their values match
if all keys in b are in target_dict and their values match
target
Mapping
The dictionary to search
The dictionary to search
query
Mapping
A query dict with keys to match
A query dict with keys to match
partial_match
bool
Should the query values be used as partial or exact matches. Defaults to :code:`True`.
Should the query values be used as partial or exact matches . Defaults to : code : ` True ` .