summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2025-01-17 22:09:56 +0100
committerSarah Boyce <42296566+sarahboyce@users.noreply.github.com>2025-01-20 14:07:28 +0100
commitf5772de69679efb54129ac1cbca3579b512778af (patch)
treeab215760e2e77124bbb8970b0913c2a99ae68743 /django
parent61dae11df52fae71fc3050974ac459f362c9dfd7 (diff)
Fixed #36005 -- Dropped support for Python 3.10 and 3.11.
Diffstat (limited to 'django')
-rw-r--r--django/db/migrations/serializer.py8
-rw-r--r--django/db/models/enums.py37
-rw-r--r--django/db/models/fields/files.py3
-rw-r--r--django/test/runner.py22
-rw-r--r--django/test/testcases.py25
-rw-r--r--django/views/debug.py29
6 files changed, 29 insertions, 95 deletions
diff --git a/django/db/migrations/serializer.py b/django/db/migrations/serializer.py
index 4f61a69cd4..eabdb24f20 100644
--- a/django/db/migrations/serializer.py
+++ b/django/db/migrations/serializer.py
@@ -16,7 +16,7 @@ from django.db import models
from django.db.migrations.operations.base import Operation
from django.db.migrations.utils import COMPILED_REGEX_TYPE, RegexObject
from django.utils.functional import LazyObject, Promise
-from django.utils.version import PY311, get_docs_version
+from django.utils.version import get_docs_version
FUNCTION_TYPES = (types.FunctionType, types.BuiltinFunctionType, types.MethodType)
@@ -140,11 +140,7 @@ class EnumSerializer(BaseSerializer):
enum_class = self.value.__class__
module = enum_class.__module__
if issubclass(enum_class, enum.Flag):
- if PY311:
- members = list(self.value)
- else:
- members, _ = enum._decompose(enum_class, self.value)
- members = reversed(members)
+ members = list(self.value)
else:
members = (self.value,)
return (
diff --git a/django/db/models/enums.py b/django/db/models/enums.py
index 54e8bf8fad..cb17fe9756 100644
--- a/django/db/models/enums.py
+++ b/django/db/models/enums.py
@@ -1,25 +1,8 @@
import enum
+from enum import EnumType, IntEnum, StrEnum
+from enum import property as enum_property
from django.utils.functional import Promise
-from django.utils.version import PY311, PY312
-
-if PY311:
- from enum import EnumType, IntEnum, StrEnum
- from enum import property as enum_property
-else:
- from enum import EnumMeta as EnumType
- from types import DynamicClassAttribute as enum_property
-
- class ReprEnum(enum.Enum):
- def __str__(self):
- return str(self.value)
-
- class IntEnum(int, ReprEnum):
- pass
-
- class StrEnum(str, ReprEnum):
- pass
-
__all__ = ["Choices", "IntegerChoices", "TextChoices"]
@@ -49,14 +32,6 @@ class ChoicesType(EnumType):
member._label_ = label
return enum.unique(cls)
- if not PY312:
-
- def __contains__(cls, member):
- if not isinstance(member, enum.Enum):
- # Allow non-enums to match against member values.
- return any(x.value == member for x in cls)
- return super().__contains__(member)
-
@property
def names(cls):
empty = ["__empty__"] if hasattr(cls, "__empty__") else []
@@ -79,13 +54,7 @@ class ChoicesType(EnumType):
class Choices(enum.Enum, metaclass=ChoicesType):
"""Class for creating enumerated choices."""
- if PY311:
- do_not_call_in_templates = enum.nonmember(True)
- else:
-
- @property
- def do_not_call_in_templates(self):
- return True
+ do_not_call_in_templates = enum.nonmember(True)
@enum_property
def label(self):
diff --git a/django/db/models/fields/files.py b/django/db/models/fields/files.py
index 0716d3599e..03c3939a4e 100644
--- a/django/db/models/fields/files.py
+++ b/django/db/models/fields/files.py
@@ -14,7 +14,6 @@ from django.db.models.fields import Field
from django.db.models.query_utils import DeferredAttribute
from django.db.models.utils import AltersData
from django.utils.translation import gettext_lazy as _
-from django.utils.version import PY311
class FieldFile(File, AltersData):
@@ -329,7 +328,7 @@ class FileField(Field):
f"File for {self.name} must have "
"the name attribute specified to be saved."
)
- if PY311 and isinstance(file._file, ContentFile):
+ if isinstance(file._file, ContentFile):
exc.add_note("Pass a 'name' argument to ContentFile.")
raise exc
diff --git a/django/test/runner.py b/django/test/runner.py
index 097980986d..c8bb16e7b3 100644
--- a/django/test/runner.py
+++ b/django/test/runner.py
@@ -28,7 +28,7 @@ from django.test.utils import setup_test_environment
from django.test.utils import teardown_databases as _teardown_databases
from django.test.utils import teardown_test_environment
from django.utils.datastructures import OrderedSet
-from django.utils.version import PY312, PY313
+from django.utils.version import PY313
try:
import ipdb as pdb
@@ -829,15 +829,14 @@ class DiscoverRunner:
"unittest -k option."
),
)
- if PY312:
- parser.add_argument(
- "--durations",
- dest="durations",
- type=int,
- default=None,
- metavar="N",
- help="Show the N slowest test cases (N=0 for all).",
- )
+ parser.add_argument(
+ "--durations",
+ dest="durations",
+ type=int,
+ default=None,
+ metavar="N",
+ help="Show the N slowest test cases (N=0 for all).",
+ )
@property
def shuffle_seed(self):
@@ -1005,9 +1004,8 @@ class DiscoverRunner:
"resultclass": self.get_resultclass(),
"verbosity": self.verbosity,
"buffer": self.buffer,
+ "durations": self.durations,
}
- if PY312:
- kwargs["durations"] = self.durations
return kwargs
def run_checks(self, databases):
diff --git a/django/test/testcases.py b/django/test/testcases.py
index 36366bd777..8f9ba977a3 100644
--- a/django/test/testcases.py
+++ b/django/test/testcases.py
@@ -54,7 +54,6 @@ from django.test.utils import (
override_settings,
)
from django.utils.functional import classproperty
-from django.utils.version import PY311
from django.views.static import serve
logger = logging.getLogger("django.test")
@@ -71,24 +70,6 @@ __all__ = (
__unittest = True
-if not PY311:
- # Backport of unittest.case._enter_context() from Python 3.11.
- def _enter_context(cm, addcleanup):
- # Look up the special methods on the type to match the with statement.
- cls = type(cm)
- try:
- enter = cls.__enter__
- exit = cls.__exit__
- except AttributeError:
- raise TypeError(
- f"'{cls.__module__}.{cls.__qualname__}' object does not support the "
- f"context manager protocol"
- ) from None
- result = enter(cm)
- addcleanup(exit, cm, None, None, None)
- return result
-
-
def to_list(value):
"""Put value into a list if it's not already one."""
if not isinstance(value, list):
@@ -398,12 +379,6 @@ class SimpleTestCase(unittest.TestCase):
"""Perform post-test things."""
pass
- if not PY311:
- # Backport of unittest.TestCase.enterClassContext() from Python 3.11.
- @classmethod
- def enterClassContext(cls, cm):
- return _enter_context(cm, cls.addClassCleanup)
-
def settings(self, **kwargs):
"""
A context manager that temporarily sets a setting and reverts to the
diff --git a/django/views/debug.py b/django/views/debug.py
index 10b4d22030..425ad296b2 100644
--- a/django/views/debug.py
+++ b/django/views/debug.py
@@ -17,7 +17,7 @@ from django.utils.datastructures import MultiValueDict
from django.utils.encoding import force_str
from django.utils.module_loading import import_string
from django.utils.regex_helper import _lazy_re_compile
-from django.utils.version import PY311, get_docs_version
+from django.utils.version import get_docs_version
from django.views.decorators.debug import coroutine_functions_to_sensitive_variables
# Minimal Django templates engine to render the error templates
@@ -567,22 +567,19 @@ class ExceptionReporter:
post_context = []
colno = tb_area_colno = ""
- if PY311:
- _, _, start_column, end_column = next(
- itertools.islice(
- tb.tb_frame.f_code.co_positions(), tb.tb_lasti // 2, None
- )
+ _, _, start_column, end_column = next(
+ itertools.islice(
+ tb.tb_frame.f_code.co_positions(), tb.tb_lasti // 2, None
)
- if start_column and end_column:
- underline = "^" * (end_column - start_column)
- spaces = " " * (start_column + len(str(lineno + 1)) + 2)
- colno = f"\n{spaces}{underline}"
- tb_area_spaces = " " * (
- 4
- + start_column
- - (len(context_line) - len(context_line.lstrip()))
- )
- tb_area_colno = f"\n{tb_area_spaces}{underline}"
+ )
+ if start_column and end_column:
+ underline = "^" * (end_column - start_column)
+ spaces = " " * (start_column + len(str(lineno + 1)) + 2)
+ colno = f"\n{spaces}{underline}"
+ tb_area_spaces = " " * (
+ 4 + start_column - (len(context_line) - len(context_line.lstrip()))
+ )
+ tb_area_colno = f"\n{tb_area_spaces}{underline}"
yield {
"exc_cause": exc_cause,
"exc_cause_explicit": exc_cause_explicit,