Skip to content

Change http.cookie.Morsel to Dict[str, any]#3060

Merged
JelleZijlstra merged 1 commit intopython:masterfrom
FlorianLudwig:master
Jun 19, 2019
Merged

Change http.cookie.Morsel to Dict[str, any]#3060
JelleZijlstra merged 1 commit intopython:masterfrom
FlorianLudwig:master

Conversation

@FlorianLudwig
Copy link
Contributor

Morsel does cast any value to string and therfor any is the correct
typehint. For some keys other types then strings are more
appropiate anyway, max-age can take an integer (unix time) and http-only
a boolean.

Closes #3059

class CookieError(Exception): ...

class Morsel(Dict[str, str], Generic[_T]):
class Morsel(Dict[str, any], Generic[_T]):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any, not any

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed, thanks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also rebased to current master.

Morsel does cast any value to string and therfor any is the correct
typehint. For some keys other types then strings are more
appropiate anyway, max-age can take an integer (unix time) and http-only
a boolean.

Closes python#3059
@JelleZijlstra JelleZijlstra merged commit 2e10326 into python:master Jun 19, 2019
@asvetlov
Copy link
Contributor

@JelleZijlstra could I ask why TypedDict from mypy_extensions cannot be used here?

@JelleZijlstra
Copy link
Member

Mostly because that wasn't the PR I received, and what was already here seemed like an improvement.

Also, there are no current usages of TypedDict in typeshed, and as long as it lives in mypy_extensions we can't expect it to work in other type checkers. It's going to be moved into typing very soon though.

@asvetlov
Copy link
Contributor

So if I create a PR that uses from typing_extensions import TypedDict would you accept it?
Note, typing_extensions looks more generic that another existing project mypy_extensions.

@JelleZijlstra
Copy link
Member

If it works with typecheckers and passes CI, sure. I think python/mypy#7028 will have to be fixed first though.

@asvetlov
Copy link
Contributor

Aha, I see. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

3 participants