The problem I had with Literal["foo"] is that at least according to mypy "foo" is a string and it was expecting Literal["foo"].
I think you're right, something must be mixed up. But then again this is the latest version of python and mypy, on intellij, so I'm not sure what I did wrong, it's using otherwise default options.
- TypedDict is an option but if you can, dataclasses work much better
- mypy does refine Optional[T] to T with an if check. Maybe you need to futz with the compiler options?
- Does Literal["foo"] not work? I've been using it with pydantic for de-serializing a tagged union of dicts and also for function args.
e.g.,