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

Add missing http.client globals and make all of them literal #13255

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
21 changes: 15 additions & 6 deletions stdlib/http/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@ class HTTPStatus(IntEnum):
def phrase(self) -> str: ...
@property
def description(self) -> str: ...

# Keep these synced with the global constants in http/client.pyi.
CONTINUE = 100
SWITCHING_PROTOCOLS = 101
PROCESSING = 102
if sys.version_info >= (3, 9):
EARLY_HINTS = 103

OK = 200
CREATED = 201
ACCEPTED = 202
Expand All @@ -27,6 +32,7 @@ class HTTPStatus(IntEnum):
MULTI_STATUS = 207
ALREADY_REPORTED = 208
IM_USED = 226

MULTIPLE_CHOICES = 300
MOVED_PERMANENTLY = 301
FOUND = 302
Expand All @@ -35,6 +41,7 @@ class HTTPStatus(IntEnum):
USE_PROXY = 305
TEMPORARY_REDIRECT = 307
PERMANENT_REDIRECT = 308

BAD_REQUEST = 400
UNAUTHORIZED = 401
PAYMENT_REQUIRED = 402
Expand All @@ -59,15 +66,22 @@ class HTTPStatus(IntEnum):
RANGE_NOT_SATISFIABLE = 416
REQUESTED_RANGE_NOT_SATISFIABLE = 416
EXPECTATION_FAILED = 417
if sys.version_info >= (3, 9):
IM_A_TEAPOT = 418
MISDIRECTED_REQUEST = 421
if sys.version_info >= (3, 13):
UNPROCESSABLE_CONTENT = 422
UNPROCESSABLE_ENTITY = 422
LOCKED = 423
FAILED_DEPENDENCY = 424
if sys.version_info >= (3, 9):
TOO_EARLY = 425
UPGRADE_REQUIRED = 426
PRECONDITION_REQUIRED = 428
TOO_MANY_REQUESTS = 429
REQUEST_HEADER_FIELDS_TOO_LARGE = 431
UNAVAILABLE_FOR_LEGAL_REASONS = 451

INTERNAL_SERVER_ERROR = 500
NOT_IMPLEMENTED = 501
BAD_GATEWAY = 502
Expand All @@ -79,12 +93,7 @@ class HTTPStatus(IntEnum):
LOOP_DETECTED = 508
NOT_EXTENDED = 510
NETWORK_AUTHENTICATION_REQUIRED = 511
MISDIRECTED_REQUEST = 421
UNAVAILABLE_FOR_LEGAL_REASONS = 451
if sys.version_info >= (3, 9):
EARLY_HINTS = 103
IM_A_TEAPOT = 418
TOO_EARLY = 425

if sys.version_info >= (3, 12):
@property
def is_informational(self) -> bool: ...
Expand Down
138 changes: 80 additions & 58 deletions stdlib/http/client.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import types
from _typeshed import MaybeNone, ReadableBuffer, SupportsRead, SupportsReadline, WriteableBuffer
from collections.abc import Callable, Iterable, Iterator, Mapping
from socket import socket
from typing import BinaryIO, TypeVar, overload
from typing import BinaryIO, Literal, TypeVar, overload
from typing_extensions import Self, TypeAlias

__all__ = [
Expand Down Expand Up @@ -39,63 +39,85 @@ _HeaderValue: TypeAlias = ReadableBuffer | str | int
HTTP_PORT: int
HTTPS_PORT: int

CONTINUE: int
SWITCHING_PROTOCOLS: int
PROCESSING: int

OK: int
CREATED: int
ACCEPTED: int
NON_AUTHORITATIVE_INFORMATION: int
NO_CONTENT: int
RESET_CONTENT: int
PARTIAL_CONTENT: int
MULTI_STATUS: int
IM_USED: int

MULTIPLE_CHOICES: int
MOVED_PERMANENTLY: int
FOUND: int
SEE_OTHER: int
NOT_MODIFIED: int
USE_PROXY: int
TEMPORARY_REDIRECT: int

BAD_REQUEST: int
UNAUTHORIZED: int
PAYMENT_REQUIRED: int
FORBIDDEN: int
NOT_FOUND: int
METHOD_NOT_ALLOWED: int
NOT_ACCEPTABLE: int
PROXY_AUTHENTICATION_REQUIRED: int
REQUEST_TIMEOUT: int
CONFLICT: int
GONE: int
LENGTH_REQUIRED: int
PRECONDITION_FAILED: int
REQUEST_ENTITY_TOO_LARGE: int
REQUEST_URI_TOO_LONG: int
UNSUPPORTED_MEDIA_TYPE: int
REQUESTED_RANGE_NOT_SATISFIABLE: int
EXPECTATION_FAILED: int
UNPROCESSABLE_ENTITY: int
LOCKED: int
FAILED_DEPENDENCY: int
UPGRADE_REQUIRED: int
PRECONDITION_REQUIRED: int
TOO_MANY_REQUESTS: int
REQUEST_HEADER_FIELDS_TOO_LARGE: int

INTERNAL_SERVER_ERROR: int
NOT_IMPLEMENTED: int
BAD_GATEWAY: int
SERVICE_UNAVAILABLE: int
GATEWAY_TIMEOUT: int
HTTP_VERSION_NOT_SUPPORTED: int
INSUFFICIENT_STORAGE: int
NOT_EXTENDED: int
NETWORK_AUTHENTICATION_REQUIRED: int
# Keep these global constants in sync with http.HTTPStatus (http/__init__.pyi).
# They are present for backward compatibility reasons.
CONTINUE: Literal[100]
SWITCHING_PROTOCOLS: Literal[101]
PROCESSING: Literal[102]
if sys.version_info >= (3, 9):
EARLY_HINTS: Literal[103]

OK: Literal[200]
CREATED: Literal[201]
ACCEPTED: Literal[202]
NON_AUTHORITATIVE_INFORMATION: Literal[203]
NO_CONTENT: Literal[204]
RESET_CONTENT: Literal[205]
PARTIAL_CONTENT: Literal[206]
MULTI_STATUS: Literal[207]
ALREADY_REPORTED: Literal[208]
IM_USED: Literal[226]

MULTIPLE_CHOICES: Literal[300]
MOVED_PERMANENTLY: Literal[301]
FOUND: Literal[302]
SEE_OTHER: Literal[303]
NOT_MODIFIED: Literal[304]
USE_PROXY: Literal[305]
TEMPORARY_REDIRECT: Literal[307]
PERMANENT_REDIRECT: Literal[308]

BAD_REQUEST: Literal[400]
UNAUTHORIZED: Literal[401]
PAYMENT_REQUIRED: Literal[402]
FORBIDDEN: Literal[403]
NOT_FOUND: Literal[404]
METHOD_NOT_ALLOWED: Literal[405]
NOT_ACCEPTABLE: Literal[406]
PROXY_AUTHENTICATION_REQUIRED: Literal[407]
REQUEST_TIMEOUT: Literal[408]
CONFLICT: Literal[409]
GONE: Literal[410]
LENGTH_REQUIRED: Literal[411]
PRECONDITION_FAILED: Literal[412]
if sys.version_info >= (3, 13):
CONTENT_TOO_LARGE: Literal[413]
REQUEST_ENTITY_TOO_LARGE: Literal[413]
if sys.version_info >= (3, 13):
URI_TOO_LONG: Literal[414]
REQUEST_URI_TOO_LONG: Literal[414]
UNSUPPORTED_MEDIA_TYPE: Literal[415]
if sys.version_info >= (3, 13):
RANGE_NOT_SATISFIABLE: Literal[416]
REQUESTED_RANGE_NOT_SATISFIABLE: Literal[416]
EXPECTATION_FAILED: Literal[417]
if sys.version_info >= (3, 9):
IM_A_TEAPOT: Literal[418]
MISDIRECTED_REQUEST: Literal[421]
if sys.version_info >= (3, 13):
UNPROCESSABLE_CONTENT: Literal[422]
UNPROCESSABLE_ENTITY: Literal[422]
LOCKED: Literal[423]
FAILED_DEPENDENCY: Literal[424]
if sys.version_info >= (3, 9):
TOO_EARLY: Literal[425]
UPGRADE_REQUIRED: Literal[426]
PRECONDITION_REQUIRED: Literal[428]
TOO_MANY_REQUESTS: Literal[429]
REQUEST_HEADER_FIELDS_TOO_LARGE: Literal[431]
UNAVAILABLE_FOR_LEGAL_REASONS: Literal[451]

INTERNAL_SERVER_ERROR: Literal[500]
NOT_IMPLEMENTED: Literal[501]
BAD_GATEWAY: Literal[502]
SERVICE_UNAVAILABLE: Literal[503]
GATEWAY_TIMEOUT: Literal[504]
HTTP_VERSION_NOT_SUPPORTED: Literal[505]
VARIANT_ALSO_NEGOTIATES: Literal[506]
INSUFFICIENT_STORAGE: Literal[507]
LOOP_DETECTED: Literal[508]
NOT_EXTENDED: Literal[510]
NETWORK_AUTHENTICATION_REQUIRED: Literal[511]

responses: dict[int, str]

Expand Down
Loading