The type declaration for http.cookies.Morsel is based on Dict[str, str] and therefor the following code is treated as a type error:
m = http.cookies.Morsel()
m['httponly'] = True
The implementation explicitly allows for max-age and expires to be integers as well:
https://github.com/python/cpython/blob/159ae24895272dce5fd53dd8e54809743e4f394f/Lib/http/cookies.py#L407
I would have liked to directly open a pull request but I am not sure what the right way to fix it is:
- Generally all attributes can be set to any type as they are cast to strings anyway so
Dict[str, any] does reflect the implementation fine.
- A
TypedDict defining all possible keys with their intended options would have to be somewhat opinionated, for example m['path']=1 is okay from the implementation point of view of Morsel but probably is not intended.
The type declaration for
http.cookies.Morselis based onDict[str, str]and therefor the following code is treated as a type error:The implementation explicitly allows for
max-ageandexpiresto be integers as well:https://github.com/python/cpython/blob/159ae24895272dce5fd53dd8e54809743e4f394f/Lib/http/cookies.py#L407
I would have liked to directly open a pull request but I am not sure what the right way to fix it is:
Dict[str, any]does reflect the implementation fine.TypedDictdefining all possible keys with their intended options would have to be somewhat opinionated, for examplem['path']=1is okay from the implementation point of view ofMorselbut probably is not intended.