summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2023-01-13 08:22:41 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2023-01-17 11:49:15 +0100
commitd6816bff73b37af05c968c009419c7c608e37307 (patch)
treea306cc06494247c2a106cff0b4b7af3c491f3902
parent9a01311d204ebf23e615a0802cedcc7b6b373826 (diff)
downloaddjango-d6816bff73b37af05c968c009419c7c608e37307.tar.gz
Refs #32365 -- Removed django.utils.timezone.utc per deprecation timeline.
-rw-r--r--django/utils/timezone.py27
-rw-r--r--docs/ref/utils.txt9
-rw-r--r--docs/releases/4.0.txt2
-rw-r--r--docs/releases/4.1.txt4
-rw-r--r--docs/releases/5.0.txt3
-rw-r--r--tests/migrations/test_writer.py23
-rw-r--r--tests/timezones/tests.py14
7 files changed, 15 insertions, 67 deletions
diff --git a/django/utils/timezone.py b/django/utils/timezone.py
index eff91667ec..ca9c817345 100644
--- a/django/utils/timezone.py
+++ b/django/utils/timezone.py
@@ -3,7 +3,6 @@ Timezone-related classes and functions.
"""
import functools
-import warnings
try:
import zoneinfo
@@ -16,10 +15,8 @@ from datetime import datetime, timedelta, timezone, tzinfo
from asgiref.local import Local
from django.conf import settings
-from django.utils.deprecation import RemovedInDjango50Warning
-__all__ = [ # noqa for utc RemovedInDjango50Warning.
- "utc",
+__all__ = [
"get_fixed_timezone",
"get_default_timezone",
"get_default_timezone_name",
@@ -38,20 +35,6 @@ __all__ = [ # noqa for utc RemovedInDjango50Warning.
]
-def __getattr__(name):
- if name != "utc":
- raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
-
- warnings.warn(
- "The django.utils.timezone.utc alias is deprecated. "
- "Please update your code to use datetime.timezone.utc instead.",
- RemovedInDjango50Warning,
- stacklevel=2,
- )
-
- return timezone.utc
-
-
def get_fixed_timezone(offset):
"""Return a tzinfo instance with a fixed offset from UTC."""
if isinstance(offset, timedelta):
@@ -279,11 +262,3 @@ def make_naive(value, timezone=None):
def _datetime_ambiguous_or_imaginary(dt, tz):
return tz.utcoffset(dt.replace(fold=not dt.fold)) != tz.utcoffset(dt)
-
-
-# RemovedInDjango50Warning.
-_DIR = dir()
-
-
-def __dir__():
- return sorted([*_DIR, "utc"])
diff --git a/docs/ref/utils.txt b/docs/ref/utils.txt
index c70c374a63..5591dfc70f 100644
--- a/docs/ref/utils.txt
+++ b/docs/ref/utils.txt
@@ -862,15 +862,6 @@ appropriate entities.
.. module:: django.utils.timezone
:synopsis: Timezone support.
-.. data:: utc
-
- :class:`~datetime.tzinfo` instance that represents UTC.
-
- .. deprecated:: 4.1
-
- This is an alias to :attr:`datetime.timezone.utc`. Use
- :attr:`datetime.timezone.utc` directly.
-
.. function:: get_fixed_timezone(offset)
Returns a :class:`~datetime.tzinfo` instance that represents a time zone
diff --git a/docs/releases/4.0.txt b/docs/releases/4.0.txt
index 74dd4dbb93..abadd54a03 100644
--- a/docs/releases/4.0.txt
+++ b/docs/releases/4.0.txt
@@ -590,7 +590,7 @@ Miscellaneous
:ref:`Localization section <use_l10n_deprecation>` above for more details.
* As part of the :ref:`move to zoneinfo <whats-new-4.0>`,
- :attr:`django.utils.timezone.utc` is changed to alias
+ ``django.utils.timezone.utc`` is changed to alias
:attr:`datetime.timezone.utc`.
* The minimum supported version of ``asgiref`` is increased from 3.3.2 to
diff --git a/docs/releases/4.1.txt b/docs/releases/4.1.txt
index 0391548e63..150195727e 100644
--- a/docs/releases/4.1.txt
+++ b/docs/releases/4.1.txt
@@ -695,8 +695,8 @@ Miscellaneous
:meth:`.RemoteUserBackend.configure_user`. Support for ``RemoteUserBackend``
subclasses that do not accept this argument is deprecated.
-* The :data:`django.utils.timezone.utc` alias to :attr:`datetime.timezone.utc`
- is deprecated. Use :attr:`datetime.timezone.utc` directly.
+* The ``django.utils.timezone.utc`` alias to :attr:`datetime.timezone.utc` is
+ deprecated. Use :attr:`datetime.timezone.utc` directly.
* Passing a response object and a form/formset name to
``SimpleTestCase.assertFormError()`` and ``assertFormsetError()`` is
diff --git a/docs/releases/5.0.txt b/docs/releases/5.0.txt
index 9c7a10c294..9ae70cbf75 100644
--- a/docs/releases/5.0.txt
+++ b/docs/releases/5.0.txt
@@ -331,3 +331,6 @@ to remove usage of these features.
* Support for logging out via ``GET`` requests in the
``django.contrib.auth.views.LogoutView`` and
``django.contrib.auth.views.logout_then_login()`` is removed.
+
+* The ``django.utils.timezone.utc`` alias to ``datetime.timezone.utc`` is
+ removed.
diff --git a/tests/migrations/test_writer.py b/tests/migrations/test_writer.py
index ce1c024b13..9c026ffb82 100644
--- a/tests/migrations/test_writer.py
+++ b/tests/migrations/test_writer.py
@@ -24,9 +24,8 @@ from django.core.validators import EmailValidator, RegexValidator
from django.db import migrations, models
from django.db.migrations.serializer import BaseSerializer
from django.db.migrations.writer import MigrationWriter, OperationWriter
-from django.test import SimpleTestCase, ignore_warnings
+from django.test import SimpleTestCase
from django.utils.deconstruct import deconstructible
-from django.utils.deprecation import RemovedInDjango50Warning
from django.utils.functional import SimpleLazyObject
from django.utils.timezone import get_default_timezone, get_fixed_timezone
from django.utils.translation import gettext_lazy as _
@@ -568,19 +567,13 @@ class WriterTests(SimpleTestCase):
datetime.datetime(2014, 1, 1, 1, 1),
("datetime.datetime(2014, 1, 1, 1, 1)", {"import datetime"}),
)
- with ignore_warnings(category=RemovedInDjango50Warning):
- from django.utils.timezone import utc
- for tzinfo in (utc, datetime.timezone.utc):
- with self.subTest(tzinfo=tzinfo):
- self.assertSerializedResultEqual(
- datetime.datetime(2012, 1, 1, 1, 1, tzinfo=tzinfo),
- (
- "datetime.datetime"
- "(2012, 1, 1, 1, 1, tzinfo=datetime.timezone.utc)",
- {"import datetime"},
- ),
- )
-
+ self.assertSerializedResultEqual(
+ datetime.datetime(2012, 1, 1, 1, 1, tzinfo=datetime.timezone.utc),
+ (
+ "datetime.datetime(2012, 1, 1, 1, 1, tzinfo=datetime.timezone.utc)",
+ {"import datetime"},
+ ),
+ )
self.assertSerializedResultEqual(
datetime.datetime(
2012, 1, 1, 2, 1, tzinfo=zoneinfo.ZoneInfo("Europe/Paris")
diff --git a/tests/timezones/tests.py b/tests/timezones/tests.py
index 89e87172f1..56784db207 100644
--- a/tests/timezones/tests.py
+++ b/tests/timezones/tests.py
@@ -33,7 +33,6 @@ from django.test import (
from django.test.utils import requires_tz_support
from django.urls import reverse
from django.utils import timezone, translation
-from django.utils.deprecation import RemovedInDjango50Warning
from django.utils.timezone import timedelta
from .forms import (
@@ -74,19 +73,6 @@ EAT = timezone.get_fixed_timezone(180) # Africa/Nairobi
ICT = timezone.get_fixed_timezone(420) # Asia/Bangkok
-class UTCAliasTests(SimpleTestCase):
- def test_alias_deprecation_warning(self):
- msg = (
- "The django.utils.timezone.utc alias is deprecated. "
- "Please update your code to use datetime.timezone.utc instead."
- )
- with self.assertRaisesMessage(RemovedInDjango50Warning, msg):
- timezone.utc
-
- def test_timezone_module_dir_includes_utc(self):
- self.assertIn("utc", dir(timezone))
-
-
@contextmanager
def override_database_connection_timezone(timezone):
try: