Closed as not planned
Description
Feature
I would like to be able to instantiate TypedDict
s in dynamic contexts, for example:
tdict: dict[str, type] = {}
tdict["foo"] = int
tdict["bar"] = bool
booOutput = TypedDict("booOutput", tdict)
def boo(**kwargs) -> booOutput:
return booOutput(**kwargs)
boo(foo=2, bar=False)
Pitch
I want to declare dynamic classes where I don't know statically what a method will return. But when I build the class I know the specific output types, and I would like to declare them so that I can rely on inspect.get_annotations
or equivalent.
If TypedDict
is not an option, is there a way that I can specify a return annotation dynamically when I create the class (a mapping return annotation)? This issue might be related. Thanks!