Skip to content

Installing types-requests breaks urllib3 2.0 type hints #10786

Closed as not planned

Description

@pquentin

requests 2.31.0 depends on urllib3, and supports both urllib3 1.21.x and urllib3 2.0.x. requests does not have inline type hints. urllib3 1.x did not have inline type hints, we introduced them in urllib3 2.0, as correctly identified here:

obsolete_since = "2.0.0" # Released on 2023-04-26

However, when taking advantages of urllib3 2.0 type hints in a file like this:

import urllib3.connection


class HTTPSConnection(urllib3.connection.HTTPSConnection):
    def connect(self) -> None:
        super().connect()
        self.foo = "bar"

mypy --strict t.py reports no error, unless I run pip install types-requests, which installs types-requests 2.31.0.6 AND types-urllib3 1.26.25.14. At this point, the typeshed package takes precedence even if I'm using urllib3 2.0.5 at runtime, and mypy --strict t.py reports:

t.py:6: error: Call to untyped function "connect" in typed context  [no-untyped-call]
Found 1 error in 1 file (checked 1 source file)

The manual fix is to manually uninstall types-urllib3, but is there a way to make this work without manual intervention?

Activity

  1. AlexWaygood commented on Sep 27, 2023

    @AlexWaygood
    Member

    Thanks for filing the issue!

    We'd like to change our types-requests package so that it depends on urllib3 rather than types-urllib3. Unfortunately, doing so breaks our tests due to a limitation of how our CI is set up -- our tests start complaining about differences between our outdated stubs for urllib3 and the inline types in the runtime package for urllib3, and it's all a bit of a mess.

    However, good news! In four days, we're due to remove our stubs for urllib3 from typeshed (#6898). Once we do so, we can easily change types-requests so that it depends on urllib3 rather than types-urllib3, which will resolve this issue for you.

    TL;DR: closing as a duplicate of #10142 ;)

  2. AlexWaygood commented on Oct 1, 2023

    @AlexWaygood
    Member

    @pquentin hopefully this is resolved with types-requests>=2.31.0.7?

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