以下のように tuple
を利用することでうまく定義できます.
from typing import Literal
choices = ["a", "b"]
choices_dict = {"a": 1, "b": 2}
Literal["a", "b"] == Literal[choices]
>>> False
Literal["a", "b"] == Literal[tuple(choices)]
>>> True
Literal["a", "b"] == Literal[choices_dict.keys()]
>>> False
Literal["a", "b"] == Literal[tuple(choices_dict.keys())]
>>> True
参考: Typing dynamically create literal alias from list of valid values