diff --git a/telegram/_utils/types.py b/telegram/_utils/types.py index 0bf8b2d98..670662f4c 100644 --- a/telegram/_utils/types.py +++ b/telegram/_utils/types.py @@ -87,7 +87,7 @@ FieldTuple = Tuple[str, bytes, str] UploadFileDict = Dict[str, FieldTuple] """Dictionary containing file data to be uploaded to the API.""" -HTTPVersion = Literal["1.1", "2.0"] +HTTPVersion = Literal["1.1", "2.0", "2"] """Allowed HTTP versions. .. versionadded:: 20.4""" diff --git a/telegram/ext/_applicationbuilder.py b/telegram/ext/_applicationbuilder.py index 918eaef7e..05278a6d0 100644 --- a/telegram/ext/_applicationbuilder.py +++ b/telegram/ext/_applicationbuilder.py @@ -592,8 +592,11 @@ class ApplicationBuilder(Generic[BT, CCT, UD, CD, BD, JQ]): Reset the default version to 1.1. Args: - http_version (:obj:`str`): Pass ``"2"`` if you'd like to use HTTP/2 for making - requests to Telegram. Defaults to ``"1.1"``, in which case HTTP/1.1 is used. + http_version (:obj:`str`): Pass ``"2"`` or ``"2.0"`` if you'd like to use HTTP/2 for + making requests to Telegram. Defaults to ``"1.1"``, in which case HTTP/1.1 is used. + + .. versionchanged:: NEXT.VERSION + Accept ``"2"`` as a valid value. Returns: :class:`ApplicationBuilder`: The same builder with the updated argument. @@ -751,8 +754,12 @@ class ApplicationBuilder(Generic[BT, CCT, UD, CD, BD, JQ]): Reset the default version to 1.1. Args: - get_updates_http_version (:obj:`str`): Pass ``"2"`` if you'd like to use HTTP/2 for - making requests to Telegram. Defaults to ``"1.1"``, in which case HTTP/1.1 is used. + get_updates_http_version (:obj:`str`): Pass ``"2"`` or ``"2.0"`` if you'd like to use + HTTP/2 for making requests to Telegram. Defaults to ``"1.1"``, in which case + HTTP/1.1 is used. + + .. versionchanged:: NEXT.VERSION + Accept ``"2"`` as a valid value. Returns: :class:`ApplicationBuilder`: The same builder with the updated argument. diff --git a/telegram/request/_httpxrequest.py b/telegram/request/_httpxrequest.py index 6d8e83045..edb1dce96 100644 --- a/telegram/request/_httpxrequest.py +++ b/telegram/request/_httpxrequest.py @@ -82,13 +82,16 @@ class HTTPXRequest(BaseRequest): With a finite pool timeout, you must expect :exc:`telegram.error.TimedOut` exceptions to be thrown when more requests are made simultaneously than there are connections in the connection pool! - http_version (:obj:`str`, optional): If ``"2"``, HTTP/2 will be used instead of HTTP/1.1. - Defaults to ``"1.1"``. + http_version (:obj:`str`, optional): If ``"2"`` or ``"2.0"``, HTTP/2 will be used instead + of HTTP/1.1. Defaults to ``"1.1"``. .. versionadded:: 20.1 .. versionchanged:: 20.2 Reset the default version to 1.1. + .. versionchanged:: NEXT.VERSION + Accept ``"2"`` as a valid value. + """ __slots__ = ("_client", "_client_kwargs", "_http_version") @@ -115,8 +118,8 @@ class HTTPXRequest(BaseRequest): max_keepalive_connections=connection_pool_size, ) - if http_version not in ("1.1", "2"): - raise ValueError("`http_version` must be either '1.1' or '2'.") + if http_version not in ("1.1", "2", "2.0"): + raise ValueError("`http_version` must be either '1.1', '2.0' or '2'.") http1 = http_version == "1.1" diff --git a/tests/request/test_request.py b/tests/request/test_request.py index 30352a516..349166ec9 100644 --- a/tests/request/test_request.py +++ b/tests/request/test_request.py @@ -85,8 +85,9 @@ class TestNoSocksHTTP2WithoutRequest: @pytest.mark.skipif(not TEST_WITH_OPT_DEPS, reason="Optional dependencies not installed") class TestHTTP2WithRequest: - async def test_http_2_response(self): - httpx_request = HTTPXRequest(http_version="2") + @pytest.mark.parametrize("http_version", ["2", "2.0"]) + async def test_http_2_response(self, http_version): + httpx_request = HTTPXRequest(http_version=http_version) async with httpx_request: resp = await httpx_request._client.request( url="https://python-telegram-bot.org",