Skip to content

requests.packages missing in types-requests 2.27.5 #6893

Closed as not planned
Closed as not planned

Description

@wpwood

When moving from types-requests 2.26.3 to 2.27.5, the following code

requests.packages.urllib3.disable_warnings(requests.packages.urllib3.exceptions.InsecureRequestWarning)

now gets a type error in mypy, error: Module has no attribute "packages"

I was able to fix the issuing by forcing mypy to use types-requests 2.26.3.

Activity

  1. JelleZijlstra commented on Jan 11, 2022

    @JelleZijlstra
    Member

    We removed it in #6859. That PR doesn't make clear why the copy in requests was removed; it seems to still exist in the most recent release of requests.

  2. wpwood commented on Jan 11, 2022

    @wpwood
    Author

    We removed it in #6859. That PR doesn't make clear why the copy in requests was removed; it seems to still exist in the most recent release of requests.

    Yeah, that was what I saw as well, that it still seems to be in requests.

  3. srittau commented on Jan 11, 2022

    @srittau
    Collaborator

    The original plan was to import the urllib3 stubs from types-urllib3 into requests.packages.urllib3 as runtime does. Unfortunately, this isn't easily possible. The requests.packages.urllib3 were quite outdated, and it's not clear which version of urllib3 we should use. It would also mean that we have to maintain two copies of urllib3. I recommend to import urllib3 imports directly from urllib3 instead of requests.packages.urllib3.

  4. Akuli commented on Jan 12, 2022

    @Akuli
    Collaborator

    The code example in this issue needs the same copy of urllib3 as requests uses internally, because it is suppressing a warning that requests generates while it is using its urllib3. I think we should add back requests/packages/__init__.pyi with a __getattr__ incomplete marker, so that the import will at least work, even if it isn't very nicely type checked.

  5. srittau commented on Jan 12, 2022

    @srittau
    Collaborator

    The __getattr__() marker is a good idea. The alternative is (your idea, I think) to basically copy the urllib3 structure and do a from urllib.xyz import * in each file, although I'd like to avoid that.

  6. andersk commented on Jan 13, 2022

    @andersk
    Contributor

    requests no longer vendors urllib3 or any other packages as of 2.16.0 (psf/requests#4067), so there’s no longer a concern as to which version to use.

    >>> import urllib3, requests.packages.urllib3
    >>> requests.packages.urllib3 is urllib3
    True
  7. added a commit that references this issue on Jan 23, 2022
  8. added a commit that references this issue on Jan 23, 2022
  9. added a commit that references this issue on Feb 4, 2022
  10. srittau commented on Jul 12, 2022

    @srittau
    Collaborator

    Closing per @andersk's comment.

  11. added a commit that references this issue on Oct 21, 2023
  12. added a commit that references this issue on Apr 22, 2024
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