async def METHOD_NAME(
    request: PythonSourceFilesRequest, union_membership: UnionMembership
) -> PythonSourceFiles:
    sources = await Get(
        SourceFiles,
        SourceFilesRequest(
            (tgt.get(SourcesField) for tgt in request.targets),
            for_sources_types=request.valid_sources_types,
            enable_codegen=True,
        ),
    )
    missing_init_files = await Get(
        AncestorFiles,
        AncestorFilesRequest(
            input_files=sources.snapshot.files, requested=("__init__.py", "__init__.pyi")
        ),
    )
    init_injected = await Get(
        Snapshot, MergeDigests((sources.snapshot.digest, missing_init_files.snapshot.digest))
    )
    # Codegen is able to generate code in any arbitrary location, unlike sources normally being
    # rooted under the target definition. To determine source roots for these generated files, we
    # cannot use the normal `SourceRootRequest.for_target()` and we instead must determine
    # a source root for every individual generated file. So, we re-resolve the codegen sources here.
    python_and_resources_targets = []
    codegen_targets = []
    for tgt in request.targets:
        if tgt.has_field(PythonSourceField) or tgt.has_field(ResourceSourceField):
            python_and_resources_targets.append(tgt)
        elif tgt.get(SourcesField).can_generate(PythonSourceField, union_membership) or tgt.get(
            SourcesField
        ).can_generate(ResourceSourceField, union_membership):
            codegen_targets.append(tgt)
    codegen_sources = await MultiGet(
        Get(
            HydratedSources,
            HydrateSourcesRequest(
                tgt.get(SourcesField),
                for_sources_types=request.valid_sources_types,
                enable_codegen=True,
            ),
        )
        for tgt in codegen_targets
    )
    source_root_requests = [
        *(SourceRootRequest.for_target(tgt) for tgt in python_and_resources_targets),
        *(
            SourceRootRequest.for_file(f)
            for sources in codegen_sources
            for f in sources.snapshot.files
        ),
    ]
    source_root_objs = await MultiGet(
        Get(SourceRoot, SourceRootRequest, req) for req in source_root_requests
    )
    source_root_paths = {source_root_obj.path for source_root_obj in source_root_objs}
    return PythonSourceFiles(
        SourceFiles(init_injected, sources.unrooted_files), tuple(sorted(source_root_paths))
    )