Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
timezone: Strengthen get_timezone type.
Anders Kaseorgfeeb39a55f7c
diff --git a/zerver/lib/timezone.py b/zerver/lib/timezone.pyindex ac88347c6f1..b043af89c51 100644--- a/zerver/lib/timezone.py+++ b/zerver/lib/timezone.py@@ -7,7 +7,7 @@ import pytzdef get_all_timezones() -> List[str]:return sorted(pytz.all_timezones)-def get_timezone(tz: str) -> datetime.tzinfo:+def get_timezone(tz: str) -> pytz.BaseTzInfo:return pytz.timezone(tz)# This method carefully trims a list of common timezones in the pytzdiff --git a/zerver/tests/test_messages.py b/zerver/tests/test_messages.pyindex 062f477f160..55d95dcec68 100644--- a/zerver/tests/test_messages.py+++ b/zerver/tests/test_messages.py@@ -2567,8 +2567,7 @@ class ScheduledMessageTest(ZulipTestCase):self.assert_json_success(result)self.assertEqual(message.content, 'Test message 6')local_tz = get_timezone(tz_guess)- # Since mypy is not able to recognize localize and normalize as attributes of tzinfo we use ignore.- utz_defer_until = local_tz.normalize(local_tz.localize(defer_until)) # type: ignore[attr-defined] # Reason in comment on previous line.+ utz_defer_until = local_tz.normalize(local_tz.localize(defer_until))self.assertEqual(message.scheduled_timestamp,convert_to_UTC(utz_defer_until))self.assertEqual(message.delivery_type, ScheduledMessage.SEND_LATER)@@ -2584,8 +2583,7 @@ class ScheduledMessageTest(ZulipTestCase):self.assert_json_success(result)self.assertEqual(message.content, 'Test message 7')local_tz = get_timezone(user.timezone)- # Since mypy is not able to recognize localize and normalize as attributes of tzinfo we use ignore.- utz_defer_until = local_tz.normalize(local_tz.localize(defer_until)) # type: ignore[attr-defined] # Reason in comment on previous line.+ utz_defer_until = local_tz.normalize(local_tz.localize(defer_until))self.assertEqual(message.scheduled_timestamp,convert_to_UTC(utz_defer_until))self.assertEqual(message.delivery_type, ScheduledMessage.SEND_LATER)diff --git a/zerver/views/message_send.py b/zerver/views/message_send.pyindex 8686f216244..0d992227050 100644--- a/zerver/views/message_send.py+++ b/zerver/views/message_send.py@@ -144,8 +144,7 @@ def handle_deferred_message(sender: UserProfile, client: Client,deliver_at_usertz = deliver_atif deliver_at_usertz.tzinfo is None:user_tz = get_timezone(local_tz)- # Since mypy is not able to recognize localize and normalize as attributes of tzinfo we use ignore.- deliver_at_usertz = user_tz.normalize(user_tz.localize(deliver_at)) # type: ignore[attr-defined] # Reason in comment on previous line.+ deliver_at_usertz = user_tz.normalize(user_tz.localize(deliver_at))deliver_at = convert_to_UTC(deliver_at_usertz)if deliver_at <= timezone_now():