Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

requests.packages missing in types-requests 2.27.5 #6893

Closed
wpwood opened this issue Jan 11, 2022 · 7 comments
Closed

requests.packages missing in types-requests 2.27.5 #6893

wpwood opened this issue Jan 11, 2022 · 7 comments

Comments

@wpwood
Copy link

wpwood commented Jan 11, 2022

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.

@JelleZijlstra
Copy link
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.

@wpwood
Copy link
Author

wpwood commented Jan 11, 2022

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.

@srittau
Copy link
Collaborator

srittau commented Jan 11, 2022

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.

@Akuli
Copy link
Collaborator

Akuli commented Jan 12, 2022

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.

@srittau
Copy link
Collaborator

srittau commented Jan 12, 2022

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.

@andersk
Copy link
Contributor

andersk commented Jan 13, 2022

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

peterschutt added a commit to peterschutt/djangorestframework-stubs that referenced this issue Jan 23, 2022
types-requests removed urllib3 stubs and [have recommended](python/typeshed#6893 (comment))
to use types-urllib3 directly.
benesch added a commit to benesch/mypy_boto3_builder that referenced this issue Jan 23, 2022
See python/typeshed#6893. The `request.packages.urllib3` module no
longer has type stubs, but there are dedicated type stubs for `urllib3`
that can be used instead.
eggplants added a commit to akamhy/waybackpy that referenced this issue Feb 4, 2022
* fix: CI yml name

* add: mypy configuraion

* add: type annotation to waybackpy modules

* add: type annotation to test modules

* fix: mypy command

* add: types-requests to dev deps

* fix: disable max-line-length

* fix: move pytest.ini into setup.cfg

* add: urllib3 to deps

* fix: Retry (ref: python/typeshed#6893)

* fix: f-string

* fix: shorten long lines

* add: staticmethod decorator to no-self-use methods

* fix: str(headers)->headers_str

* fix: error message

* fix: revert "str(headers)->headers_str" and ignore assignment CaseInsensitiveDict with str

* fix: mypy error
@srittau
Copy link
Collaborator

srittau commented Jul 12, 2022

Closing per @andersk's comment.

@srittau srittau closed this as not planned Won't fix, can't repro, duplicate, stale Jul 12, 2022
beliaev-maksim added a commit to beliaev-maksim/responses that referenced this issue Oct 20, 2023
markstory pushed a commit to getsentry/responses that referenced this issue Oct 21, 2023
* remove dependency on urllib3 vendored in requests since it is not maintained anymore. See python/typeshed#6893 (comment)
* new version of mypy does not require overloads for type checking
* [skip] remove pragma comment
btbrand added a commit to btbrand/responses that referenced this issue Apr 22, 2024
* remove dependency on urllib3 vendored in requests since it is not maintained anymore. See python/typeshed#6893 (comment)
* new version of mypy does not require overloads for type checking
* [skip] remove pragma comment
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

No branches or pull requests

5 participants