diff --git a/django/utils/version.py b/django/utils/version.py index 4569abb608..7d17da318f 100644 --- a/django/utils/version.py +++ b/django/utils/version.py @@ -2,8 +2,18 @@ import datetime import functools import os import subprocess +import sys from distutils.version import LooseVersion +# Private, stable API for detecting the Python version. PYXY means "Python X.Y +# or later". So that third-party apps can use these values, each constant +# should remain as long as the oldest supported Django version supports that +# Python version. +PY36 = sys.version_info >= (3, 6) +PY37 = sys.version_info >= (3, 7) +PY38 = sys.version_info >= (3, 8) +PY39 = sys.version_info >= (3, 9) + def get_version(version=None): """Return a PEP 440-compliant version number from VERSION.""" diff --git a/tests/admin_scripts/tests.py b/tests/admin_scripts/tests.py index 096984032f..e56d43c4bc 100644 --- a/tests/admin_scripts/tests.py +++ b/tests/admin_scripts/tests.py @@ -26,10 +26,10 @@ from django.db.migrations.recorder import MigrationRecorder from django.test import ( LiveServerTestCase, SimpleTestCase, TestCase, override_settings, ) +from django.utils.version import PY36 custom_templates_dir = os.path.join(os.path.dirname(__file__), 'custom_templates') -PY36 = sys.version_info >= (3, 6) SYSTEM_CHECK_MSG = 'System check identified no issues' diff --git a/tests/migrations/test_writer.py b/tests/migrations/test_writer.py index 0aeb2e5b99..5c9aa85c55 100644 --- a/tests/migrations/test_writer.py +++ b/tests/migrations/test_writer.py @@ -5,7 +5,6 @@ import functools import math import os import re -import sys import uuid from unittest import mock @@ -25,11 +24,10 @@ from django.utils.deconstruct import deconstructible from django.utils.functional import SimpleLazyObject from django.utils.timezone import FixedOffset, get_default_timezone, utc from django.utils.translation import gettext_lazy as _ +from django.utils.version import PY36 from .models import FoodManager, FoodQuerySet -PY36 = sys.version_info >= (3, 6) - class Money(decimal.Decimal): def deconstruct(self): diff --git a/tests/view_tests/tests/test_debug.py b/tests/view_tests/tests/test_debug.py index b677fd98c9..f0b2d017d4 100644 --- a/tests/view_tests/tests/test_debug.py +++ b/tests/view_tests/tests/test_debug.py @@ -19,6 +19,7 @@ from django.urls import reverse from django.utils.encoding import force_bytes from django.utils.functional import SimpleLazyObject from django.utils.safestring import mark_safe +from django.utils.version import PY36 from django.views.debug import ( CLEANSED_SUBSTITUTE, CallableSettingWrapper, ExceptionReporter, cleanse_setting, technical_500_response, @@ -31,8 +32,6 @@ from ..views import ( sensitive_method_view, sensitive_view, ) -PY36 = sys.version_info >= (3, 6) - class User: def __str__(self):