Bag Generic Typing

How would people feel about making dask.bag.Bag a generic type, so that type checkers and function signatures could include the information about what’s in a dask bag. For example

def add_lengths(bag: dask.bag.Bag[list[dict[str, Any]]]) -> dask.bag.Bag[list[dict[str, Any]]]:
    return bag.map(add_length)

def add_length(item: dict[str, Any]) -> dict[str, Any]:
    item["length"] = len(item["document"])

I’d be happy to write a PR for this.

Hi @jordan-jack-schneide, welcome to Dask community!

Thanks for proposing this!

As this is a technical proposal for Dask new feature, I would recommend you raise directly an issue on github for this, you might get faster and direct feedback from core developers.

Ah thanks! Wasn’t sure what the right place was. I’ll copy this over there.

1 Like