Skip to content

types-requests: hook vs list-of-hooks #7088

Closed

Description

@UncleOwen

Typechecking this program

import requests

session = requests.Session()
session.hooks = {
   'response': lambda r, *args, **kwargs: r.raise_for_status()
}

fails with

foo.py:5: error: Dict entry 0 has incompatible type "str": "Callable[[Any, VarArg(Any), KwArg(Any)], Any]"; expected "str": "List[Callable[[Response], Any]]"
Found 1 error in 1 file (checked 1 source file)

although the code works.

Changing this line to

_Hooks = MutableMapping[Text, Union[_Hook,list[_Hook]]]

fixes this for me. Should I open a pull request?

Activity

  1. srittau commented on Jan 31, 2022

    @srittau
    Collaborator

    Sounds right to me (except that we use | syntax instead of Union in typeshed). PR welcome!

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

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