mirror of https://github.com/django/django.git
Refs #34233 -- Used types.NoneType.
Available since Python 3.10 where it was reintroduced.
This commit is contained in:
parent
26a395f27d
commit
fd21f82aa8
|
@ -28,6 +28,7 @@
|
||||||
"""
|
"""
|
||||||
from ctypes import byref, c_char_p, c_int
|
from ctypes import byref, c_char_p, c_int
|
||||||
from enum import IntEnum
|
from enum import IntEnum
|
||||||
|
from types import NoneType
|
||||||
|
|
||||||
from django.contrib.gis.gdal.base import GDALBase
|
from django.contrib.gis.gdal.base import GDALBase
|
||||||
from django.contrib.gis.gdal.error import SRSException
|
from django.contrib.gis.gdal.error import SRSException
|
||||||
|
@ -57,7 +58,7 @@ class SpatialReference(GDALBase):
|
||||||
EPSG code, a PROJ string, and/or a projection "well known" shorthand
|
EPSG code, a PROJ string, and/or a projection "well known" shorthand
|
||||||
string (one of 'WGS84', 'WGS72', 'NAD27', 'NAD83').
|
string (one of 'WGS84', 'WGS72', 'NAD27', 'NAD83').
|
||||||
"""
|
"""
|
||||||
if not isinstance(axis_order, (type(None), AxisOrder)):
|
if not isinstance(axis_order, (NoneType, AxisOrder)):
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
"SpatialReference.axis_order must be an AxisOrder instance."
|
"SpatialReference.axis_order must be an AxisOrder instance."
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
from types import NoneType
|
||||||
|
|
||||||
from django.contrib.postgres.indexes import OpClass
|
from django.contrib.postgres.indexes import OpClass
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
from django.db import DEFAULT_DB_ALIAS, NotSupportedError
|
from django.db import DEFAULT_DB_ALIAS, NotSupportedError
|
||||||
|
@ -45,13 +47,13 @@ class ExclusionConstraint(BaseConstraint):
|
||||||
isinstance(expr, (list, tuple)) and len(expr) == 2 for expr in expressions
|
isinstance(expr, (list, tuple)) and len(expr) == 2 for expr in expressions
|
||||||
):
|
):
|
||||||
raise ValueError("The expressions must be a list of 2-tuples.")
|
raise ValueError("The expressions must be a list of 2-tuples.")
|
||||||
if not isinstance(condition, (type(None), Q)):
|
if not isinstance(condition, (NoneType, Q)):
|
||||||
raise ValueError("ExclusionConstraint.condition must be a Q instance.")
|
raise ValueError("ExclusionConstraint.condition must be a Q instance.")
|
||||||
if not isinstance(deferrable, (type(None), Deferrable)):
|
if not isinstance(deferrable, (NoneType, Deferrable)):
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
"ExclusionConstraint.deferrable must be a Deferrable instance."
|
"ExclusionConstraint.deferrable must be a Deferrable instance."
|
||||||
)
|
)
|
||||||
if not isinstance(include, (type(None), list, tuple)):
|
if not isinstance(include, (NoneType, list, tuple)):
|
||||||
raise ValueError("ExclusionConstraint.include must be a list or tuple.")
|
raise ValueError("ExclusionConstraint.include must be a list or tuple.")
|
||||||
self.expressions = expressions
|
self.expressions = expressions
|
||||||
self.index_type = index_type or "GIST"
|
self.index_type = index_type or "GIST"
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
|
from types import NoneType
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.core.checks import Error
|
from django.core.checks import Error
|
||||||
|
|
||||||
|
|
||||||
def check_site_id(app_configs, **kwargs):
|
def check_site_id(app_configs, **kwargs):
|
||||||
if hasattr(settings, "SITE_ID") and not isinstance(
|
if hasattr(settings, "SITE_ID") and not isinstance(
|
||||||
settings.SITE_ID, (type(None), int)
|
settings.SITE_ID, (NoneType, int)
|
||||||
):
|
):
|
||||||
return [
|
return [
|
||||||
Error("The SITE_ID setting must be an integer", id="sites.E101"),
|
Error("The SITE_ID setting must be an integer", id="sites.E101"),
|
||||||
|
|
|
@ -304,7 +304,7 @@ class TypeSerializer(BaseSerializer):
|
||||||
def serialize(self):
|
def serialize(self):
|
||||||
special_cases = [
|
special_cases = [
|
||||||
(models.Model, "models.Model", ["from django.db import models"]),
|
(models.Model, "models.Model", ["from django.db import models"]),
|
||||||
(type(None), "type(None)", []),
|
(types.NoneType, "types.NoneType", ["import types"]),
|
||||||
]
|
]
|
||||||
for case, string, imports in special_cases:
|
for case, string, imports in special_cases:
|
||||||
if case is self.value:
|
if case is self.value:
|
||||||
|
@ -338,7 +338,7 @@ class Serializer:
|
||||||
(datetime.date, datetime.timedelta, datetime.time): DateTimeSerializer,
|
(datetime.date, datetime.timedelta, datetime.time): DateTimeSerializer,
|
||||||
SettingsReference: SettingsReferenceSerializer,
|
SettingsReference: SettingsReferenceSerializer,
|
||||||
float: FloatSerializer,
|
float: FloatSerializer,
|
||||||
(bool, int, type(None), bytes, str, range): BaseSimpleSerializer,
|
(bool, int, types.NoneType, bytes, str, range): BaseSimpleSerializer,
|
||||||
decimal.Decimal: DecimalSerializer,
|
decimal.Decimal: DecimalSerializer,
|
||||||
(functools.partial, functools.partialmethod): FunctoolsPartialSerializer,
|
(functools.partial, functools.partialmethod): FunctoolsPartialSerializer,
|
||||||
(
|
(
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
|
from types import NoneType
|
||||||
|
|
||||||
from django.core.exceptions import FieldError, ValidationError
|
from django.core.exceptions import FieldError, ValidationError
|
||||||
from django.db import connections
|
from django.db import connections
|
||||||
|
@ -148,7 +149,7 @@ class UniqueConstraint(BaseConstraint):
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
"UniqueConstraint.fields and expressions are mutually exclusive."
|
"UniqueConstraint.fields and expressions are mutually exclusive."
|
||||||
)
|
)
|
||||||
if not isinstance(condition, (type(None), Q)):
|
if not isinstance(condition, (NoneType, Q)):
|
||||||
raise ValueError("UniqueConstraint.condition must be a Q instance.")
|
raise ValueError("UniqueConstraint.condition must be a Q instance.")
|
||||||
if condition and deferrable:
|
if condition and deferrable:
|
||||||
raise ValueError("UniqueConstraint with conditions cannot be deferred.")
|
raise ValueError("UniqueConstraint with conditions cannot be deferred.")
|
||||||
|
@ -163,11 +164,11 @@ class UniqueConstraint(BaseConstraint):
|
||||||
"UniqueConstraint.opclasses cannot be used with expressions. "
|
"UniqueConstraint.opclasses cannot be used with expressions. "
|
||||||
"Use django.contrib.postgres.indexes.OpClass() instead."
|
"Use django.contrib.postgres.indexes.OpClass() instead."
|
||||||
)
|
)
|
||||||
if not isinstance(deferrable, (type(None), Deferrable)):
|
if not isinstance(deferrable, (NoneType, Deferrable)):
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
"UniqueConstraint.deferrable must be a Deferrable instance."
|
"UniqueConstraint.deferrable must be a Deferrable instance."
|
||||||
)
|
)
|
||||||
if not isinstance(include, (type(None), list, tuple)):
|
if not isinstance(include, (NoneType, list, tuple)):
|
||||||
raise ValueError("UniqueConstraint.include must be a list or tuple.")
|
raise ValueError("UniqueConstraint.include must be a list or tuple.")
|
||||||
if not isinstance(opclasses, (list, tuple)):
|
if not isinstance(opclasses, (list, tuple)):
|
||||||
raise ValueError("UniqueConstraint.opclasses must be a list or tuple.")
|
raise ValueError("UniqueConstraint.opclasses must be a list or tuple.")
|
||||||
|
|
|
@ -4,6 +4,7 @@ import functools
|
||||||
import inspect
|
import inspect
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
|
from types import NoneType
|
||||||
from uuid import UUID
|
from uuid import UUID
|
||||||
|
|
||||||
from django.core.exceptions import EmptyResultSet, FieldError, FullResultSet
|
from django.core.exceptions import EmptyResultSet, FieldError, FullResultSet
|
||||||
|
@ -506,7 +507,6 @@ class Expression(BaseExpression, Combinable):
|
||||||
# The current approach for NULL is based on lowest common denominator behavior
|
# The current approach for NULL is based on lowest common denominator behavior
|
||||||
# i.e. if one of the supported databases is raising an error (rather than
|
# i.e. if one of the supported databases is raising an error (rather than
|
||||||
# return NULL) for `val <op> NULL`, then Django raises FieldError.
|
# return NULL) for `val <op> NULL`, then Django raises FieldError.
|
||||||
NoneType = type(None)
|
|
||||||
|
|
||||||
_connector_combinations = [
|
_connector_combinations = [
|
||||||
# Numeric operations - operands of same type.
|
# Numeric operations - operands of same type.
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
from types import NoneType
|
||||||
|
|
||||||
from django.db.backends.utils import names_digest, split_identifier
|
from django.db.backends.utils import names_digest, split_identifier
|
||||||
from django.db.models.expressions import Col, ExpressionList, F, Func, OrderBy
|
from django.db.models.expressions import Col, ExpressionList, F, Func, OrderBy
|
||||||
from django.db.models.functions import Collate
|
from django.db.models.functions import Collate
|
||||||
|
@ -26,7 +28,7 @@ class Index:
|
||||||
):
|
):
|
||||||
if opclasses and not name:
|
if opclasses and not name:
|
||||||
raise ValueError("An index must be named to use opclasses.")
|
raise ValueError("An index must be named to use opclasses.")
|
||||||
if not isinstance(condition, (type(None), Q)):
|
if not isinstance(condition, (NoneType, Q)):
|
||||||
raise ValueError("Index.condition must be a Q instance.")
|
raise ValueError("Index.condition must be a Q instance.")
|
||||||
if condition and not name:
|
if condition and not name:
|
||||||
raise ValueError("An index must be named to use condition.")
|
raise ValueError("An index must be named to use condition.")
|
||||||
|
@ -58,7 +60,7 @@ class Index:
|
||||||
raise ValueError("Index.fields must contain only strings with field names.")
|
raise ValueError("Index.fields must contain only strings with field names.")
|
||||||
if include and not name:
|
if include and not name:
|
||||||
raise ValueError("A covering index must be named.")
|
raise ValueError("A covering index must be named.")
|
||||||
if not isinstance(include, (type(None), list, tuple)):
|
if not isinstance(include, (NoneType, list, tuple)):
|
||||||
raise ValueError("Index.include must be a list or tuple.")
|
raise ValueError("Index.include must be a list or tuple.")
|
||||||
self.fields = list(fields)
|
self.fields = list(fields)
|
||||||
# A list of 2-tuple with the field name and ordering ('' or 'DESC').
|
# A list of 2-tuple with the field name and ordering ('' or 'DESC').
|
||||||
|
|
|
@ -2,6 +2,7 @@ import codecs
|
||||||
import datetime
|
import datetime
|
||||||
import locale
|
import locale
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
|
from types import NoneType
|
||||||
from urllib.parse import quote
|
from urllib.parse import quote
|
||||||
|
|
||||||
from django.utils.functional import Promise
|
from django.utils.functional import Promise
|
||||||
|
@ -34,7 +35,7 @@ def smart_str(s, encoding="utf-8", strings_only=False, errors="strict"):
|
||||||
|
|
||||||
|
|
||||||
_PROTECTED_TYPES = (
|
_PROTECTED_TYPES = (
|
||||||
type(None),
|
NoneType,
|
||||||
int,
|
int,
|
||||||
float,
|
float,
|
||||||
Decimal,
|
Decimal,
|
||||||
|
|
|
@ -9,6 +9,7 @@ import re
|
||||||
import sys
|
import sys
|
||||||
import uuid
|
import uuid
|
||||||
import zoneinfo
|
import zoneinfo
|
||||||
|
from types import NoneType
|
||||||
from unittest import mock
|
from unittest import mock
|
||||||
|
|
||||||
import custom_migration_operations.more_operations
|
import custom_migration_operations.more_operations
|
||||||
|
@ -797,7 +798,7 @@ class WriterTests(SimpleTestCase):
|
||||||
self.assertEqual(result.keywords, value.keywords)
|
self.assertEqual(result.keywords, value.keywords)
|
||||||
|
|
||||||
def test_serialize_type_none(self):
|
def test_serialize_type_none(self):
|
||||||
self.assertSerializedEqual(type(None))
|
self.assertSerializedEqual(NoneType)
|
||||||
|
|
||||||
def test_serialize_type_model(self):
|
def test_serialize_type_model(self):
|
||||||
self.assertSerializedEqual(models.Model)
|
self.assertSerializedEqual(models.Model)
|
||||||
|
|
Loading…
Reference in New Issue