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: Allow session headers to be of type None #7773

Merged
merged 14 commits into from
May 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions stubs/requests/requests/api.pyi
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
from typing import Any

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

def request(
method: str | bytes,
url: str | bytes,
*,
params: _Params | None = ...,
data: _Data | None = ...,
headers: _TextMapping | None = ...,
headers: _HeadersMapping | None = ...,
cookies: RequestsCookieJar | _TextMapping | None = ...,
files: _Files | None = ...,
auth: _Auth | None = ...,
Expand All @@ -27,7 +39,7 @@ def get(
params: _Params | None = ...,
*,
data: _Data | None = ...,
headers: _TextMapping | None = ...,
headers: _HeadersMapping | None = ...,
cookies: RequestsCookieJar | _TextMapping | None = ...,
files: _Files | None = ...,
auth: _Auth | None = ...,
Expand All @@ -45,7 +57,7 @@ def options(
*,
params: _Params | None = ...,
data: _Data | None = ...,
headers: _TextMapping | None = ...,
headers: _HeadersMapping | None = ...,
cookies: RequestsCookieJar | _TextMapping | None = ...,
files: _Files | None = ...,
auth: _Auth | None = ...,
Expand All @@ -63,7 +75,7 @@ def head(
*,
params: _Params | None = ...,
data: _Data | None = ...,
headers: _TextMapping | None = ...,
headers: _HeadersMapping | None = ...,
cookies: RequestsCookieJar | _TextMapping | None = ...,
files: _Files | None = ...,
auth: _Auth | None = ...,
Expand All @@ -82,7 +94,7 @@ def post(
json: Any | None = ...,
*,
params: _Params | None = ...,
headers: _TextMapping | None = ...,
headers: _HeadersMapping | None = ...,
cookies: RequestsCookieJar | _TextMapping | None = ...,
files: _Files | None = ...,
auth: _Auth | None = ...,
Expand All @@ -99,7 +111,7 @@ def put(
data: _Data | None = ...,
*,
params: _Params | None = ...,
headers: _TextMapping | None = ...,
headers: _HeadersMapping | None = ...,
cookies: RequestsCookieJar | _TextMapping | None = ...,
files: _Files | None = ...,
auth: _Auth | None = ...,
Expand All @@ -117,7 +129,7 @@ def patch(
data: _Data | None = ...,
*,
params: _Params | None = ...,
headers: _TextMapping | None = ...,
headers: _HeadersMapping | None = ...,
cookies: RequestsCookieJar | _TextMapping | None = ...,
files: _Files | None = ...,
auth: _Auth | None = ...,
Expand All @@ -135,7 +147,7 @@ def delete(
*,
params: _Params | None = ...,
data: _Data | None = ...,
headers: _TextMapping | None = ...,
headers: _HeadersMapping | None = ...,
cookies: RequestsCookieJar | _TextMapping | None = ...,
files: _Files | None = ...,
auth: _Auth | None = ...,
Expand Down
28 changes: 19 additions & 9 deletions stubs/requests/requests/sessions.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,22 @@ _Params: TypeAlias = Union[
str | bytes,
]
_TextMapping: TypeAlias = MutableMapping[str, str]
_HeadersMapping: TypeAlias = MutableMapping[str, str] | MutableMapping[str, bytes] | MutableMapping[str, str | bytes]
_HeadersUpdateMapping: TypeAlias = (
MutableMapping[str, str]
| MutableMapping[str, bytes]
| MutableMapping[str, None]
| MutableMapping[str, str | bytes]
| MutableMapping[str, str | None]
| MutableMapping[str, bytes | None]
| MutableMapping[str, str | bytes | None]
)
_Timeout: TypeAlias = Union[float, tuple[float, float], tuple[float, None]]
_Verify: TypeAlias = bool | str

class Session(SessionRedirectMixin):
__attrs__: Any
headers: CaseInsensitiveDict[str]
headers: CaseInsensitiveDict[str | bytes]
auth: _Auth | None
proxies: _TextMapping
hooks: _Hooks
Expand All @@ -95,7 +105,7 @@ class Session(SessionRedirectMixin):
url: str | bytes,
params: _Params | None = ...,
data: _Data | None = ...,
headers: _TextMapping | None = ...,
headers: _HeadersUpdateMapping | None = ...,
cookies: None | RequestsCookieJar | _TextMapping = ...,
files: _Files | None = ...,
auth: _Auth | None = ...,
Expand All @@ -114,7 +124,7 @@ class Session(SessionRedirectMixin):
*,
params: _Params | None = ...,
data: _Data | None = ...,
headers: _TextMapping | None = ...,
headers: _HeadersUpdateMapping | None = ...,
cookies: RequestsCookieJar | _TextMapping | None = ...,
files: _Files | None = ...,
auth: _Auth | None = ...,
Expand All @@ -133,7 +143,7 @@ class Session(SessionRedirectMixin):
*,
params: _Params | None = ...,
data: _Data | None = ...,
headers: _TextMapping | None = ...,
headers: _HeadersUpdateMapping | None = ...,
cookies: RequestsCookieJar | _TextMapping | None = ...,
files: _Files | None = ...,
auth: _Auth | None = ...,
Expand All @@ -152,7 +162,7 @@ class Session(SessionRedirectMixin):
*,
params: _Params | None = ...,
data: _Data | None = ...,
headers: _TextMapping | None = ...,
headers: _HeadersUpdateMapping | None = ...,
cookies: RequestsCookieJar | _TextMapping | None = ...,
files: _Files | None = ...,
auth: _Auth | None = ...,
Expand All @@ -172,7 +182,7 @@ class Session(SessionRedirectMixin):
json: Any | None = ...,
*,
params: _Params | None = ...,
headers: _TextMapping | None = ...,
headers: _HeadersUpdateMapping | None = ...,
cookies: RequestsCookieJar | _TextMapping | None = ...,
files: _Files | None = ...,
auth: _Auth | None = ...,
Expand All @@ -190,7 +200,7 @@ class Session(SessionRedirectMixin):
data: _Data | None = ...,
*,
params: _Params | None = ...,
headers: _TextMapping | None = ...,
headers: _HeadersUpdateMapping | None = ...,
cookies: RequestsCookieJar | _TextMapping | None = ...,
files: _Files | None = ...,
auth: _Auth | None = ...,
Expand All @@ -209,7 +219,7 @@ class Session(SessionRedirectMixin):
data: _Data | None = ...,
*,
params: _Params | None = ...,
headers: _TextMapping | None = ...,
headers: _HeadersUpdateMapping | None = ...,
cookies: RequestsCookieJar | _TextMapping | None = ...,
files: _Files | None = ...,
auth: _Auth | None = ...,
Expand All @@ -228,7 +238,7 @@ class Session(SessionRedirectMixin):
*,
params: _Params | None = ...,
data: _Data | None = ...,
headers: _TextMapping | None = ...,
headers: _HeadersUpdateMapping | None = ...,
cookies: RequestsCookieJar | _TextMapping | None = ...,
files: _Files | None = ...,
auth: _Auth | None = ...,
Expand Down