From 19ad973a299187f256fcbfac0ea38ffcaaab578b Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Fri, 6 May 2022 00:03:15 +0100 Subject: [PATCH] Add `http.HTTPMethod` https://github.com/python/cpython/pull/91997 `description` isn't actually read-only at runtime, but I don't think there's any other way of telling type checkers "this is an attribute that the members have, not a member itself". And pretending it's a property is already what we do for `HTTPStatus`, which has the same issue. --- stdlib/http/__init__.pyi | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/stdlib/http/__init__.pyi b/stdlib/http/__init__.pyi index 822cc0932939..10c1d5926e84 100644 --- a/stdlib/http/__init__.pyi +++ b/stdlib/http/__init__.pyi @@ -2,7 +2,13 @@ import sys from enum import IntEnum from typing_extensions import Literal -__all__ = ["HTTPStatus"] +if sys.version_info >= (3, 11): + from enum import StrEnum + +if sys.version_info >= (3, 11): + __all__ = ["HTTPStatus", "HTTPMethod"] +else: + __all__ = ["HTTPStatus"] class HTTPStatus(IntEnum): @property @@ -74,3 +80,17 @@ class HTTPStatus(IntEnum): EARLY_HINTS: Literal[103] IM_A_TEAPOT: Literal[418] TOO_EARLY: Literal[425] + +if sys.version_info >= (3, 11): + class HTTPMethod(StrEnum): + @property + def description(self) -> str: ... + CONNECT: str + DELETE: str + GET: str + HEAD: str + OPTIONS: str + PATCH: str + POST: str + PUT: str + TRACE: str