Skip to content

http.cookies.Morsel type for flags should allow for bool #3059

@FlorianLudwig

Description

@FlorianLudwig

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:

  1. 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.
  2. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions