Is it possible to make a TypedDict with a set of known keys and then a type for an arbitrary key? For example, in TypeScript, I could do this:
interface Sample {
x: boolean;
y: number;
[name: string]: string;
}
What is the equivalent in Python?
Edit: My problem is that I make a library where a function's argument expects a type of Mapping[str, SomeCustomClass]
. I want to change the type so that there are now special keys, where the types are like this:
labels: Mapping[str, str]
aliases: Mapping[str, List[str]]
But I want it to still be an arbitrary mapping where if a key is not in the two special cases above, it should be of type SomeCustomClass
. What is a good way to do this? I am not interested in making a backwards-incompatible change if there is an alternative.