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

Conversation

bswck
Copy link

@bswck bswck commented Dec 16, 2024

Generated with https://gist.github.com/bswck/4b41f8329f602ef7d92e65a8721ec9ae (against typeshed upstream), so I'm pretty sure it doesn't annotate any codes incorrectly.
I discussed the idea of turning these global ints to Literals with @JelleZijlstra.

What's left to do is examine why stubtest allegedly reported no issues with the previous version of the http/client.pyi stub that lacked some constants from runtime.
That's what I'll investigate tomorrow.

This comment has been minimized.

@bswck
Copy link
Author

bswck commented Dec 16, 2024

BTW, FYI the order of those globals follows exactly the order of which they are originally defined in the enum @ http/__init__.pyi:

CONTINUE = 100
SWITCHING_PROTOCOLS = 101
PROCESSING = 102
OK = 200
CREATED = 201
ACCEPTED = 202
NON_AUTHORITATIVE_INFORMATION = 203
NO_CONTENT = 204
RESET_CONTENT = 205
PARTIAL_CONTENT = 206
MULTI_STATUS = 207
ALREADY_REPORTED = 208
IM_USED = 226
MULTIPLE_CHOICES = 300
MOVED_PERMANENTLY = 301
FOUND = 302
SEE_OTHER = 303
NOT_MODIFIED = 304
USE_PROXY = 305
TEMPORARY_REDIRECT = 307
PERMANENT_REDIRECT = 308
BAD_REQUEST = 400
UNAUTHORIZED = 401
PAYMENT_REQUIRED = 402
FORBIDDEN = 403
NOT_FOUND = 404
METHOD_NOT_ALLOWED = 405
NOT_ACCEPTABLE = 406
PROXY_AUTHENTICATION_REQUIRED = 407
REQUEST_TIMEOUT = 408
CONFLICT = 409
GONE = 410
LENGTH_REQUIRED = 411
PRECONDITION_FAILED = 412
if sys.version_info >= (3, 13):
CONTENT_TOO_LARGE = 413
REQUEST_ENTITY_TOO_LARGE = 413
if sys.version_info >= (3, 13):
URI_TOO_LONG = 414
REQUEST_URI_TOO_LONG = 414
UNSUPPORTED_MEDIA_TYPE = 415
if sys.version_info >= (3, 13):
RANGE_NOT_SATISFIABLE = 416
REQUESTED_RANGE_NOT_SATISFIABLE = 416
EXPECTATION_FAILED = 417
if sys.version_info >= (3, 13):
UNPROCESSABLE_CONTENT = 422
UNPROCESSABLE_ENTITY = 422
LOCKED = 423
FAILED_DEPENDENCY = 424
UPGRADE_REQUIRED = 426
PRECONDITION_REQUIRED = 428
TOO_MANY_REQUESTS = 429
REQUEST_HEADER_FIELDS_TOO_LARGE = 431
INTERNAL_SERVER_ERROR = 500
NOT_IMPLEMENTED = 501
BAD_GATEWAY = 502
SERVICE_UNAVAILABLE = 503
GATEWAY_TIMEOUT = 504
HTTP_VERSION_NOT_SUPPORTED = 505
VARIANT_ALSO_NEGOTIATES = 506
INSUFFICIENT_STORAGE = 507
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

I also assumed the stub is up-to-date with the source, but I'll make sure later.

Also, I think it's reasonable to add a comment like "keep in sync with the http.HTTPStatus enum" here, WDYT?

@AlexWaygood
Copy link
Member

What's left to do is examine why stubtest allegedly reported no issues with the previous version of the http/client.pyi stub that lacked some constants from runtime.

If a runtime module explicitly defines __all__, this is understood by stubtest as an explicit statement of "these are the public-API constants; everything else should be understood as private". In general, stubs should only reflect the public API, so if __all__ is defined, stubtest will not complain about anything that is not in __all__ at runtime being missing from the stubs

@bswck bswck force-pushed the http-client-globals-literal branch from 89e76ce to 6a6f9ae Compare December 17, 2024 17:12
@bswck
Copy link
Author

bswck commented Dec 17, 2024

While checking against the upstream of stdlib, I decided to reorder and reformat both the enum members and the annotated constants to follow exactly the order and format from there.
I also added a note for maintainers/contributors about keeping http.HTTPStatus and http.client.* in sync.

Copy link
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

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

Successfully merging this pull request may close these issues.

2 participants