Skip to content

gen.multi() return type isn't ergonomicΒ #3514

@jrheard

Description

@jrheard

Hi! This is a followup to #3478 - thanks for accepting that PR.

Now that I've updated my project to use the latest version of Tornado, gen.multi() is much nicer about the inputs I want to pass to it, but its outputs are kind of a pain to use. Currently it returns list | dict, which means that if I do result = gen.multi(a_dict), type checkers make me do assert isinstance(result, dict) before I can do anything useful with result.

I have a minimal repro here: https://github.com/jrheard/tornado-gen-repro/blob/main/main.py , which gives this mypy output (and similar output in pyright):

πŸš‚  uv run mypy main.py
main.py:24: error: Argument 1 to "takes_list" has incompatible type "list[Any] | dict[Any, Any]"; expected "list[int]"  [arg-type]
main.py:25: error: Argument 1 to "takes_dict" has incompatible type "list[Any] | dict[Any, Any]"; expected "dict[str, int]"  [arg-type]
Found 2 errors in 1 file (checked 1 source file)

I think that it should be possible to use typing.overload to make multi()'s return value a bit easier to use. I hope to submit a PR shortly!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions