Ejemplo n.º 1
0
def is_session_class(node: NodeNG) -> bool:
    """True if node represents the requests.Session class."""

    try:
        for inferred in node.infer():
            if (
                isinstance(inferred, nodes.ClassDef)
                and inferred.name == SESSION_CLASS_NAME
                and isinstance(inferred.parent, nodes.Module)
                and inferred.parent.name == SESSION_MODULE
            ):
                return True
    except InferenceError:
        pass

    return False
Ejemplo n.º 2
0
def _check_key_in_kwargs(unpacked: NodeNG, key: str) -> bool:
    """Given a **kwargs node in a function call, tries to check presence of a key."""

    try:
        for inferred in unpacked.infer():
            if (
                isinstance(inferred, nodes.Dict)
                and inferred.items
                and not _check_key_in_dict(inferred, key)
            ):
                # only if we know that it is a dict and astroid inferred some values
                return False
    except InferenceError:
        pass

    return True