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

Additional typing hints for requests #7696

Merged
merged 10 commits into from
Apr 27, 2022
30 changes: 0 additions & 30 deletions stubs/requests/@tests/stubtest_allowlist.txt
Original file line number Diff line number Diff line change
@@ -1,39 +1,9 @@
requests.Session.delete
requests.Session.get
requests.Session.head
requests.Session.options
requests.Session.patch
requests.Session.post
requests.Session.put
requests.adapters.PoolManager.connection_from_host
requests.adapters.PoolManager.connection_from_url
requests.adapters.PoolManager.urlopen
requests.api.delete
requests.api.get
requests.api.head
requests.api.options
requests.api.patch
requests.api.post
requests.api.put
requests.api.request
requests.delete
requests.get
requests.head
requests.models.RequestField.__init__
requests.models.RequestField.from_tuples
requests.options
requests.packages.VendorAlias
requests.patch
requests.post
requests.put
requests.request
requests.sessions.Session.delete
requests.sessions.Session.get
requests.sessions.Session.head
requests.sessions.Session.options
requests.sessions.Session.patch
requests.sessions.Session.post
requests.sessions.Session.put
requests.sessions.SessionRedirectMixin.resolve_redirects
requests.structures.LookupDict.__getattr__
requests.structures.LookupDict.get
188 changes: 98 additions & 90 deletions stubs/requests/requests/api.pyi
Original file line number Diff line number Diff line change
@@ -1,142 +1,150 @@
from typing import Any

from .models import Response
from .sessions import _Data, _Params
from .sessions import RequestsCookieJar, _Auth, _Cert, _Data, _Files, _HooksInput, _Params, _TextMapping, _Timeout, _Verify

def request(
method: str | bytes,
method: str,
Copy link
Member

Choose a reason for hiding this comment

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

Why change this? Seems like bytes works fine, even if it is a little weird:

>>> import requests
>>> requests.request(b'GET', 'https://www.bbc.com/news')
<Response [200]>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, you're right! Changed it back.

The implementation for url has an explicit check+conversion for bytes, which is not there for method. They also call .upper() on it, but apparently that also works for bytes :-)

Akuli marked this conversation as resolved.
Show resolved Hide resolved
url: str | bytes,
*,
params: _Params | None = ...,
data: Any | None = ...,
headers: Any | None = ...,
cookies: Any | None = ...,
files: Any | None = ...,
auth: Any | None = ...,
timeout: Any | None = ...,
data: _Data | None = ...,
headers: _TextMapping | None = ...,
cookies: RequestsCookieJar | _TextMapping | None = ...,
files: _Files | None = ...,
auth: _Auth | None = ...,
timeout: _Timeout | None = ...,
allow_redirects: bool = ...,
proxies: Any | None = ...,
hooks: Any | None = ...,
stream: Any | None = ...,
verify: Any | None = ...,
cert: Any | None = ...,
proxies: _TextMapping | None = ...,
hooks: _HooksInput | None = ...,
stream: bool | None = ...,
verify: _Verify | None = ...,
cert: _Cert | None = ...,
json: Any | None = ...,
) -> Response: ...
def get(
url: str | bytes,
params: _Params | None = ...,
data: Any | None = ...,
headers: Any | None = ...,
cookies: Any | None = ...,
files: Any | None = ...,
auth: Any | None = ...,
timeout: Any | None = ...,
*,
data: _Data | None = ...,
headers: _TextMapping | None = ...,
cookies: RequestsCookieJar | _TextMapping | None = ...,
files: _Files | None = ...,
auth: _Auth | None = ...,
timeout: _Timeout | None = ...,
allow_redirects: bool = ...,
proxies: Any | None = ...,
hooks: Any | None = ...,
stream: Any | None = ...,
verify: Any | None = ...,
cert: Any | None = ...,
proxies: _TextMapping | None = ...,
hooks: _HooksInput | None = ...,
stream: bool | None = ...,
verify: _Verify | None = ...,
cert: _Cert | None = ...,
json: Any | None = ...,
) -> Response: ...
def options(
url: str | bytes,
*,
params: _Params | None = ...,
data: Any | None = ...,
headers: Any | None = ...,
cookies: Any | None = ...,
files: Any | None = ...,
auth: Any | None = ...,
timeout: Any | None = ...,
data: _Data | None = ...,
headers: _TextMapping | None = ...,
cookies: RequestsCookieJar | _TextMapping | None = ...,
files: _Files | None = ...,
auth: _Auth | None = ...,
timeout: _Timeout | None = ...,
allow_redirects: bool = ...,
proxies: Any | None = ...,
hooks: Any | None = ...,
stream: Any | None = ...,
verify: Any | None = ...,
cert: Any | None = ...,
proxies: _TextMapping | None = ...,
hooks: _HooksInput | None = ...,
stream: bool | None = ...,
verify: _Verify | None = ...,
cert: _Cert | None = ...,
json: Any | None = ...,
) -> Response: ...
def head(
url: str | bytes,
*,
params: _Params | None = ...,
data: Any | None = ...,
headers: Any | None = ...,
cookies: Any | None = ...,
files: Any | None = ...,
auth: Any | None = ...,
timeout: Any | None = ...,
data: _Data | None = ...,
headers: _TextMapping | None = ...,
cookies: RequestsCookieJar | _TextMapping | None = ...,
files: _Files | None = ...,
auth: _Auth | None = ...,
timeout: _Timeout | None = ...,
allow_redirects: bool = ...,
proxies: Any | None = ...,
hooks: Any | None = ...,
stream: Any | None = ...,
verify: Any | None = ...,
cert: Any | None = ...,
proxies: _TextMapping | None = ...,
hooks: _HooksInput | None = ...,
stream: bool | None = ...,
verify: _Verify | None = ...,
cert: _Cert | None = ...,
json: Any | None = ...,
) -> Response: ...
def post(
url: str | bytes,
data: _Data = ...,
data: _Data | None = ...,
json: Any | None = ...,
*,
params: _Params | None = ...,
headers: Any | None = ...,
cookies: Any | None = ...,
files: Any | None = ...,
auth: Any | None = ...,
timeout: Any | None = ...,
headers: _TextMapping | None = ...,
cookies: RequestsCookieJar | _TextMapping | None = ...,
files: _Files | None = ...,
auth: _Auth | None = ...,
timeout: _Timeout | None = ...,
allow_redirects: bool = ...,
proxies: Any | None = ...,
hooks: Any | None = ...,
stream: Any | None = ...,
verify: Any | None = ...,
cert: Any | None = ...,
proxies: _TextMapping | None = ...,
hooks: _HooksInput | None = ...,
stream: bool | None = ...,
verify: _Verify | None = ...,
cert: _Cert | None = ...,
) -> Response: ...
def put(
url: str | bytes,
data: _Data = ...,
data: _Data | None = ...,
*,
params: _Params | None = ...,
headers: Any | None = ...,
cookies: Any | None = ...,
files: Any | None = ...,
auth: Any | None = ...,
timeout: Any | None = ...,
headers: _TextMapping | None = ...,
cookies: RequestsCookieJar | _TextMapping | None = ...,
files: _Files | None = ...,
auth: _Auth | None = ...,
timeout: _Timeout | None = ...,
allow_redirects: bool = ...,
proxies: Any | None = ...,
hooks: Any | None = ...,
stream: Any | None = ...,
verify: Any | None = ...,
cert: Any | None = ...,
proxies: _TextMapping | None = ...,
hooks: _HooksInput | None = ...,
stream: bool | None = ...,
verify: _Verify | None = ...,
cert: _Cert | None = ...,
json: Any | None = ...,
) -> Response: ...
def patch(
url: str | bytes,
data: _Data = ...,
data: _Data | None = ...,
*,
params: _Params | None = ...,
headers: Any | None = ...,
cookies: Any | None = ...,
files: Any | None = ...,
auth: Any | None = ...,
timeout: Any | None = ...,
headers: _TextMapping | None = ...,
cookies: RequestsCookieJar | _TextMapping | None = ...,
files: _Files | None = ...,
auth: _Auth | None = ...,
timeout: _Timeout | None = ...,
allow_redirects: bool = ...,
proxies: Any | None = ...,
hooks: Any | None = ...,
stream: Any | None = ...,
verify: Any | None = ...,
cert: Any | None = ...,
proxies: _TextMapping | None = ...,
hooks: _HooksInput | None = ...,
stream: bool | None = ...,
verify: _Verify | None = ...,
cert: _Cert | None = ...,
json: Any | None = ...,
) -> Response: ...
def delete(
url: str | bytes,
*,
params: _Params | None = ...,
data: Any | None = ...,
headers: Any | None = ...,
cookies: Any | None = ...,
files: Any | None = ...,
auth: Any | None = ...,
timeout: Any | None = ...,
data: _Data | None = ...,
headers: _TextMapping | None = ...,
cookies: RequestsCookieJar | _TextMapping | None = ...,
files: _Files | None = ...,
auth: _Auth | None = ...,
timeout: _Timeout | None = ...,
allow_redirects: bool = ...,
proxies: Any | None = ...,
hooks: Any | None = ...,
stream: Any | None = ...,
verify: Any | None = ...,
cert: Any | None = ...,
proxies: _TextMapping | None = ...,
hooks: _HooksInput | None = ...,
stream: bool | None = ...,
verify: _Verify | None = ...,
cert: _Cert | None = ...,
json: Any | None = ...,
) -> Response: ...
Loading