From ad384a4eeaa05138982efe8c2188b76391781c2b Mon Sep 17 00:00:00 2001 From: Harshil <37377066+harshil21@users.noreply.github.com> Date: Fri, 13 Jun 2025 11:42:15 +0400 Subject: [PATCH 01/10] Add support for Python 3.14 betas --- .github/workflows/unit_tests.yml | 4 +--- pyproject.toml | 5 +++++ tests/README.rst | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/workflows/unit_tests.yml b/.github/workflows/unit_tests.yml index 8181097eedb..94fa3c53cc6 100644 --- a/.github/workflows/unit_tests.yml +++ b/.github/workflows/unit_tests.yml @@ -21,7 +21,7 @@ jobs: runs-on: ${{matrix.os}} strategy: matrix: - python-version: ['3.9', '3.10', '3.11', '3.12', '3.13'] + python-version: ['3.9', '3.10', '3.11', '3.12', '3.13', '3.14.0-beta.2'] os: [ubuntu-latest, windows-latest, macos-latest] fail-fast: False steps: @@ -62,8 +62,6 @@ jobs: # Test the rest export TEST_WITH_OPT_DEPS='true' - # need to manually install pytz here, because it's no longer in the optional reqs - pip install .[all] pytz # `-n auto --dist worksteal` uses pytest-xdist to run tests on multiple CPU # workers. Increasing number of workers has little effect on test duration, but it seems # to increase flakyness. diff --git a/pyproject.toml b/pyproject.toml index 66589c25b0e..975cf99c1e2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -36,9 +36,11 @@ classifiers = [ "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", "Programming Language :: Python :: 3.13", + "Programming Language :: Python :: 3.14", ] dependencies = [ "httpx >=0.27,<0.29", + "httpcore >=1.0.9; python_version >= '3.14'" # httpx needs an update so 3.14 support works ] [project.urls] @@ -111,6 +113,8 @@ tests = [ # For testing with timezones. Might not be needed on all systems, but to ensure that unit tests # run correctly on all systems, we include it here. "tzdata", + # We've deprecated support pytz, but we still need it for testing that it works with the library. + "pytz", ] docs = [ "chango~=0.4.0; python_version >= '3.12'", @@ -123,6 +127,7 @@ docs = [ "sphinx-inline-tabs==2023.4.21", # Temporary. See #4387 "sphinx-build-compatibility @ git+https://github.com/readthedocs/sphinx-build-compatibility.git@58aabc5f207c6c2421f23d3578adc0b14af57047", + "pydantic @ git+https://github.com/pydantic/pydantic; python_version >= '3.14'" # Temporary for 3.14 support, we're waiting for a new pydantic version ] all = ["pre-commit", { include-group = "tests" }, { include-group = "docs" }] diff --git a/tests/README.rst b/tests/README.rst index 822c90d35c7..77fbd7b1855 100644 --- a/tests/README.rst +++ b/tests/README.rst @@ -42,7 +42,7 @@ such that tests marked with ``@pytest.mark.xdist_group("name")`` are run on the .. code-block:: bash - $ pytest -n auto --dist=loadgroup + $ pytest -n auto --dist=worksteal This will result in a significant speedup, but may cause some tests to fail. If you want to run the failed tests in isolation, you can use the ``--lf`` flag: From 795ff6d455035fbba41e7977a7224fad5e14eb85 Mon Sep 17 00:00:00 2001 From: harshil21 <37377066+harshil21@users.noreply.github.com> Date: Fri, 13 Jun 2025 07:50:07 +0000 Subject: [PATCH 02/10] Add chango fragment for PR #4825 --- changes/unreleased/4825.R7wiTzvN37KAV656s9kfnC.toml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 changes/unreleased/4825.R7wiTzvN37KAV656s9kfnC.toml diff --git a/changes/unreleased/4825.R7wiTzvN37KAV656s9kfnC.toml b/changes/unreleased/4825.R7wiTzvN37KAV656s9kfnC.toml new file mode 100644 index 00000000000..4d3ee6fc892 --- /dev/null +++ b/changes/unreleased/4825.R7wiTzvN37KAV656s9kfnC.toml @@ -0,0 +1,5 @@ +other = "Add support for Python 3.14 beta" +[[pull_requests]] +uid = "4825" +author_uid = "harshil21" +closes_threads = [] From eefeac46559fd78c71f8102e4983b9f5e253b544 Mon Sep 17 00:00:00 2001 From: Harshil <37377066+harshil21@users.noreply.github.com> Date: Fri, 13 Jun 2025 12:07:32 +0400 Subject: [PATCH 03/10] Fix installing with pip? --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 975cf99c1e2..71b4f70b9f9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -127,7 +127,7 @@ docs = [ "sphinx-inline-tabs==2023.4.21", # Temporary. See #4387 "sphinx-build-compatibility @ git+https://github.com/readthedocs/sphinx-build-compatibility.git@58aabc5f207c6c2421f23d3578adc0b14af57047", - "pydantic @ git+https://github.com/pydantic/pydantic; python_version >= '3.14'" # Temporary for 3.14 support, we're waiting for a new pydantic version + "pydantic @ git+https://github.com/pydantic/pydantic ; python_version >= '3.14'" # Temporary for 3.14 support, we're waiting for a new pydantic version ] all = ["pre-commit", { include-group = "tests" }, { include-group = "docs" }] From 4f66992744577ad29a0d07293e792c4dfd975e3e Mon Sep 17 00:00:00 2001 From: Harshil <37377066+harshil21@users.noreply.github.com> Date: Fri, 13 Jun 2025 12:15:40 +0400 Subject: [PATCH 04/10] I'm a little dumb --- .github/workflows/unit_tests.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/unit_tests.yml b/.github/workflows/unit_tests.yml index 94fa3c53cc6..710b9670a02 100644 --- a/.github/workflows/unit_tests.yml +++ b/.github/workflows/unit_tests.yml @@ -59,7 +59,8 @@ jobs: TO_TEST="test_no_passport.py or test_datetime.py or test_defaults.py or test_jobqueue.py or test_applicationbuilder.py or test_ratelimiter.py or test_updater.py or test_callbackdatacache.py or test_request.py" pytest -v --cov -k "${TO_TEST}" --junit-xml=.test_report_no_optionals_junit.xml opt_dep_status=$? - + + pip install .[all] # Test the rest export TEST_WITH_OPT_DEPS='true' # `-n auto --dist worksteal` uses pytest-xdist to run tests on multiple CPU From b8f512596e804309364b91233a2ea4a7944e4807 Mon Sep 17 00:00:00 2001 From: Harshil <37377066+harshil21@users.noreply.github.com> Date: Fri, 13 Jun 2025 12:40:12 +0400 Subject: [PATCH 05/10] Fix coverage not working on py 3.14 --- .github/workflows/unit_tests.yml | 1 - pyproject.toml | 6 ++++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/unit_tests.yml b/.github/workflows/unit_tests.yml index 710b9670a02..c4ff327b773 100644 --- a/.github/workflows/unit_tests.yml +++ b/.github/workflows/unit_tests.yml @@ -36,7 +36,6 @@ jobs: - name: Install dependencies run: | python -W ignore -m pip install --upgrade pip - python -W ignore -m pip install -U pytest-cov python -W ignore -m pip install . --group tests - name: Test with pytest diff --git a/pyproject.toml b/pyproject.toml index 71b4f70b9f9..0f62e585f6f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -115,6 +115,8 @@ tests = [ "tzdata", # We've deprecated support pytz, but we still need it for testing that it works with the library. "pytz", + # Install coverage: + "pytest-cov" ] docs = [ "chango~=0.4.0; python_version >= '3.12'", @@ -279,6 +281,10 @@ omit = [ "tests/", "src/telegram/__main__.py" ] +# Relevant for python 3.14: https://github.com/nedbat/coveragepy/issues/1983 +disable_warnings = [ + "no-ctracer", +] [tool.coverage.report] exclude_also = [ From f2f3285f28148634a821de616bb1c4d1d3704eb1 Mon Sep 17 00:00:00 2001 From: Harshil <37377066+harshil21@users.noreply.github.com> Date: Fri, 13 Jun 2025 13:03:32 +0400 Subject: [PATCH 06/10] Fix filter tests --- tests/ext/test_filters.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/ext/test_filters.py b/tests/ext/test_filters.py index ae125c98a40..f9db49905fd 100644 --- a/tests/ext/test_filters.py +++ b/tests/ext/test_filters.py @@ -18,6 +18,7 @@ # along with this program. If not, see [http://www.gnu.org/licenses/]. import datetime as dtm import inspect +import platform import re import pytest @@ -711,7 +712,9 @@ def test_filters_document_type(self, update): assert not filters.Document.WAV.check_update(update) assert not filters.Document.AUDIO.check_update(update) - update.message.document.mime_type = "audio/x-wav" + update.message.document.mime_type = ( + "audio/x-wav" if platform.python_version_tuple() < ("3", "14") else "audio/vnd.wave" + ) assert filters.Document.WAV.check_update(update) assert filters.Document.AUDIO.check_update(update) assert not filters.Document.XML.check_update(update) From 992f76d38f4ca34b74bfdc0c19ea6d956efd1a67 Mon Sep 17 00:00:00 2001 From: Harshil <37377066+harshil21@users.noreply.github.com> Date: Fri, 13 Jun 2025 13:09:29 +0400 Subject: [PATCH 07/10] Fix condition (copilot sucks sometimes) --- tests/ext/test_filters.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ext/test_filters.py b/tests/ext/test_filters.py index f9db49905fd..6802db2a206 100644 --- a/tests/ext/test_filters.py +++ b/tests/ext/test_filters.py @@ -713,7 +713,7 @@ def test_filters_document_type(self, update): assert not filters.Document.AUDIO.check_update(update) update.message.document.mime_type = ( - "audio/x-wav" if platform.python_version_tuple() < ("3", "14") else "audio/vnd.wave" + "audio/x-wav" if int(platform.python_version_tuple()[1]) < 14 else "audio/vnd.wave" ) assert filters.Document.WAV.check_update(update) assert filters.Document.AUDIO.check_update(update) From 41c2a62ab52870875f9f2b824de5661e66c645c7 Mon Sep 17 00:00:00 2001 From: Harshil <37377066+harshil21@users.noreply.github.com> Date: Mon, 16 Jun 2025 13:32:25 +0400 Subject: [PATCH 08/10] Review: add comments and update changleog --- .github/workflows/unit_tests.yml | 2 +- changes/unreleased/4825.R7wiTzvN37KAV656s9kfnC.toml | 2 +- pyproject.toml | 13 +++++++------ 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/.github/workflows/unit_tests.yml b/.github/workflows/unit_tests.yml index c4ff327b773..98b50c6c0c0 100644 --- a/.github/workflows/unit_tests.yml +++ b/.github/workflows/unit_tests.yml @@ -59,9 +59,9 @@ jobs: pytest -v --cov -k "${TO_TEST}" --junit-xml=.test_report_no_optionals_junit.xml opt_dep_status=$? - pip install .[all] # Test the rest export TEST_WITH_OPT_DEPS='true' + pip install .[all] # `-n auto --dist worksteal` uses pytest-xdist to run tests on multiple CPU # workers. Increasing number of workers has little effect on test duration, but it seems # to increase flakyness. diff --git a/changes/unreleased/4825.R7wiTzvN37KAV656s9kfnC.toml b/changes/unreleased/4825.R7wiTzvN37KAV656s9kfnC.toml index 4d3ee6fc892..5f932e8254d 100644 --- a/changes/unreleased/4825.R7wiTzvN37KAV656s9kfnC.toml +++ b/changes/unreleased/4825.R7wiTzvN37KAV656s9kfnC.toml @@ -1,4 +1,4 @@ -other = "Add support for Python 3.14 beta" +other = "Add Python 3.14 Beta To Test Matrix. *Python 3.14 is not officially supported by PTB yet!*" [[pull_requests]] uid = "4825" author_uid = "harshil21" diff --git a/pyproject.toml b/pyproject.toml index 0f62e585f6f..a9dc2ac0dbc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -40,7 +40,6 @@ classifiers = [ ] dependencies = [ "httpx >=0.27,<0.29", - "httpcore >=1.0.9; python_version >= '3.14'" # httpx needs an update so 3.14 support works ] [project.urls] @@ -129,7 +128,13 @@ docs = [ "sphinx-inline-tabs==2023.4.21", # Temporary. See #4387 "sphinx-build-compatibility @ git+https://github.com/readthedocs/sphinx-build-compatibility.git@58aabc5f207c6c2421f23d3578adc0b14af57047", - "pydantic @ git+https://github.com/pydantic/pydantic ; python_version >= '3.14'" # Temporary for 3.14 support, we're waiting for a new pydantic version + # For python 3.14 support, we need a version of pydantic-core >= 2.35.0, since it upgrades the + # rust toolchain, required for building the project. But there isn't a version of pydantic + # which allows that pydantic-core version yet, so we use the latest commit on the + # pydantic repository, which has the required version of pydantic-core. + # This should ideally be done in `chango`'s dependencies. We can remove this once a new pydantic + # version is released. + "pydantic @ git+https://github.com/pydantic/pydantic ; python_version >= '3.14'" ] all = ["pre-commit", { include-group = "tests" }, { include-group = "docs" }] @@ -281,10 +286,6 @@ omit = [ "tests/", "src/telegram/__main__.py" ] -# Relevant for python 3.14: https://github.com/nedbat/coveragepy/issues/1983 -disable_warnings = [ - "no-ctracer", -] [tool.coverage.report] exclude_also = [ From a81f7b1c7a20688fca3ea65ca2978254297c11a8 Mon Sep 17 00:00:00 2001 From: Harshil <37377066+harshil21@users.noreply.github.com> Date: Mon, 16 Jun 2025 14:30:17 +0400 Subject: [PATCH 09/10] Bump pytest and tornado since they officially support 3.14 --- pyproject.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index a9dc2ac0dbc..12c7d5df4d8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -92,7 +92,7 @@ socks = [ ] webhooks = [ # tornado is rather stable, but let's not allow the next major release without prior testing - "tornado~=6.4", + "tornado~=6.5", ] [dependency-groups] @@ -100,7 +100,7 @@ tests = [ # required for building the wheels for releases "build", # For the test suite - "pytest==8.3.5", + "pytest==8.4.0", # needed because pytest doesn't come with native support for coroutines as tests "pytest-asyncio==0.21.2", # xdist runs tests in parallel From e694a100a81a65b795a68992fb45e75b912f71ee Mon Sep 17 00:00:00 2001 From: Harshil <37377066+harshil21@users.noreply.github.com> Date: Thu, 19 Jun 2025 02:25:30 +0400 Subject: [PATCH 10/10] Bump to python 3.13 beta 3 --- .github/workflows/unit_tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/unit_tests.yml b/.github/workflows/unit_tests.yml index 98b50c6c0c0..a4fd47910c2 100644 --- a/.github/workflows/unit_tests.yml +++ b/.github/workflows/unit_tests.yml @@ -21,7 +21,7 @@ jobs: runs-on: ${{matrix.os}} strategy: matrix: - python-version: ['3.9', '3.10', '3.11', '3.12', '3.13', '3.14.0-beta.2'] + python-version: ['3.9', '3.10', '3.11', '3.12', '3.13', '3.14.0-beta.3'] os: [ubuntu-latest, windows-latest, macos-latest] fail-fast: False steps: