From 29e4ccb1a2d5aab21fbd7effcd48d33dc73f9b1e Mon Sep 17 00:00:00 2001 From: Nick Pope Date: Fri, 7 May 2021 18:20:14 +0100 Subject: [PATCH] Fixed #32738 -- Deprecated django.utils.datetime_safe module. --- django/utils/datetime_safe.py | 8 ++++++++ docs/internals/deprecation.txt | 2 ++ docs/releases/4.0.txt | 2 ++ tests/utils_tests/test_datetime_safe.py | 7 +++++-- 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/django/utils/datetime_safe.py b/django/utils/datetime_safe.py index c732f29ef1..e06887b706 100644 --- a/django/utils/datetime_safe.py +++ b/django/utils/datetime_safe.py @@ -8,10 +8,18 @@ # '0010/08/02 was a Monday' import time +import warnings from datetime import date as real_date, datetime as real_datetime +from django.utils.deprecation import RemovedInDjango50Warning from django.utils.regex_helper import _lazy_re_compile +warnings.warn( + 'The django.utils.datetime_safe module is deprecated.', + category=RemovedInDjango50Warning, + stacklevel=2, +) + class date(real_date): def strftime(self, fmt): diff --git a/docs/internals/deprecation.txt b/docs/internals/deprecation.txt index e3896cb136..da15e4871e 100644 --- a/docs/internals/deprecation.txt +++ b/docs/internals/deprecation.txt @@ -19,6 +19,8 @@ details on these changes. * The undocumented ``django.utils.baseconv`` module will be removed. +* The undocumented ``django.utils.datetime_safe`` module will be removed. + .. _deprecation-removed-in-4.1: 4.1 diff --git a/docs/releases/4.0.txt b/docs/releases/4.0.txt index 45dc67203d..fdd4b6c39b 100644 --- a/docs/releases/4.0.txt +++ b/docs/releases/4.0.txt @@ -437,6 +437,8 @@ Miscellaneous * The undocumented ``django.utils.baseconv`` module is deprecated. +* The undocumented ``django.utils.datetime_safe`` module is deprecated. + Features removed in 4.0 ======================= diff --git a/tests/utils_tests/test_datetime_safe.py b/tests/utils_tests/test_datetime_safe.py index 049a0dea13..b5ee3d0cad 100644 --- a/tests/utils_tests/test_datetime_safe.py +++ b/tests/utils_tests/test_datetime_safe.py @@ -1,7 +1,10 @@ from datetime import date as original_date, datetime as original_datetime -from django.test import SimpleTestCase -from django.utils.datetime_safe import date, datetime +from django.test import SimpleTestCase, ignore_warnings +from django.utils.deprecation import RemovedInDjango50Warning + +with ignore_warnings(category=RemovedInDjango50Warning): + from django.utils.datetime_safe import date, datetime class DatetimeTests(SimpleTestCase):