-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Open
Description
This problem arose from trying to type the environ
argument for a WSGI application. There are specific keys of the environ
dict that have non-str
types, and then all the other keys are HTTP_
variables (or server-defined variables, which can be ignored for this purpose) with type str
(or Text
, depending on the version of Python).
I would like to get stronger typing on environ
than Dict[str, Any]
, but there isn't a way to do that with TypedDict
currently because the set of possible keys is unbounded (the client can send any HTTP header).
Ideally, I'd like to be able to do something like:
EnvironDict = TypedDict("EnvironDict", {
"wsgi.version": Tuple[int, int],
"wsgi.input": IO[str],
# ...
}, default_type=str, total=False)
and have this mean that any key is allowed in the dictionary and all unknown keys get a value type of str
.
noyainrain, DMR-coding, gu1p, tuukkamustonen, untitaker and 30 more