import types
from typing import List
from typing import Set


def _is_code_for_function(
    code: types.CodeType, parents: List[types.CodeType], func_codes: Set[types.CodeType]
):
    """
    Check if this is the code object for a function or inside a function

    Args:
      code: The code object to check

      parents: List of parents for this code object

      func_codes: Set of code objects that are directly for functions
    """
    return code in func_codes or any(p in func_codes for p in parents)