NickC
(Nick)
1
How do I correctly annotate a dict containing a list of str and a class:
local_dict: dict[(str, Any)] = {"oRequest": Process.oRequest, "oResponse": self}
Both oRequest and self are classes instances of their respective classes (Request & Response).
Use a TypedDict.
In the unlikely scenario that self is a class (a type, don’t think that’s what you meant):
from typing import TypedDict
class MyDict(TypedDict):
oRequest: type[Process.oRequest]
oResponse: type[self]
If you instead meant self was an instance of a class (call it C), replace type[self] with C. Similar for Process.oRequest.
Finally, you can annotate local_dict with type MyDict.