mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2025-03-14 19:48:57 +01:00
Mark pytz support as deprecated
This commit is contained in:
parent
1945ce7c73
commit
e846251242
3 changed files with 31 additions and 1 deletions
3
.github/workflows/unit_tests.yml
vendored
3
.github/workflows/unit_tests.yml
vendored
|
@ -64,7 +64,8 @@ jobs:
|
|||
|
||||
# Test the rest
|
||||
export TEST_WITH_OPT_DEPS='true'
|
||||
pip install .[all]
|
||||
# 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.
|
||||
|
|
|
@ -59,6 +59,11 @@ class Defaults:
|
|||
inputs appearing throughout PTB, i.e. if a timezone naive date(time) object is passed
|
||||
somewhere, it will be assumed to be in :paramref:`tzinfo`. Defaults to
|
||||
:attr:`datetime.timezone.utc` otherwise.
|
||||
|
||||
.. deprecated:: NEXT.VERSION
|
||||
Support for ``pytz`` timezones is deprecated and will be removed in future
|
||||
versions.
|
||||
|
||||
block (:obj:`bool`, optional): Default setting for the :paramref:`BaseHandler.block`
|
||||
parameter
|
||||
of handlers and error handlers registered through :meth:`Application.add_handler` and
|
||||
|
@ -146,6 +151,19 @@ class Defaults:
|
|||
self._block: bool = block
|
||||
self._protect_content: Optional[bool] = protect_content
|
||||
|
||||
if "pytz" in str(self._tzinfo.__class__):
|
||||
# TODO: When dropping support, make sure to update _utils.datetime accordingly
|
||||
warn(
|
||||
message=PTBDeprecationWarning(
|
||||
version="NEXT.VERSION",
|
||||
message=(
|
||||
"Support for pytz timezones is deprecated and will be removed in "
|
||||
"future versions."
|
||||
),
|
||||
),
|
||||
stacklevel=2,
|
||||
)
|
||||
|
||||
if disable_web_page_preview is not None and link_preview_options is not None:
|
||||
raise ValueError(
|
||||
"`disable_web_page_preview` and `link_preview_options` are mutually exclusive."
|
||||
|
|
|
@ -25,6 +25,7 @@ import pytest
|
|||
from telegram import LinkPreviewOptions, User
|
||||
from telegram.ext import Defaults
|
||||
from telegram.warnings import PTBDeprecationWarning
|
||||
from tests.auxil.envvars import TEST_WITH_OPT_DEPS
|
||||
from tests.auxil.slots import mro_slots
|
||||
|
||||
|
||||
|
@ -39,6 +40,16 @@ class TestDefaults:
|
|||
defaults = Defaults()
|
||||
assert defaults.tzinfo is dtm.timezone.utc
|
||||
|
||||
@pytest.mark.skipif(not TEST_WITH_OPT_DEPS, reason="pytz not installed")
|
||||
def test_pytz_deprecation(self, recwarn):
|
||||
import pytz
|
||||
|
||||
with pytest.warns(PTBDeprecationWarning, match="pytz") as record:
|
||||
Defaults(tzinfo=pytz.timezone("Europe/Berlin"))
|
||||
|
||||
assert record[0].category == PTBDeprecationWarning
|
||||
assert record[0].filename == __file__, "wrong stacklevel!"
|
||||
|
||||
def test_data_assignment(self):
|
||||
defaults = Defaults()
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue