Skip to content

Cleanup dependencies and conditions for unsupported Python versions #9681

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 14 additions & 16 deletions rest_framework/utils/serializer_helpers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import contextlib
import sys
from collections.abc import Mapping, MutableMapping

from django.utils.encoding import force_str
Expand Down Expand Up @@ -29,21 +28,20 @@ def __reduce__(self):
# but preserve the raw data.
return (dict, (dict(self),))

if sys.version_info >= (3, 9):
# These are basically copied from OrderedDict, with `serializer` added.
def __or__(self, other):
if not isinstance(other, dict):
return NotImplemented
new = self.__class__(self, serializer=self.serializer)
new.update(other)
return new

def __ror__(self, other):
if not isinstance(other, dict):
return NotImplemented
new = self.__class__(other, serializer=self.serializer)
new.update(self)
return new
# These are basically copied from OrderedDict, with `serializer` added.
def __or__(self, other):
if not isinstance(other, dict):
return NotImplemented
new = self.__class__(self, serializer=self.serializer)
new.update(other)
return new

def __ror__(self, other):
if not isinstance(other, dict):
return NotImplemented
new = self.__class__(other, serializer=self.serializer)
new.update(self)
return new


class ReturnList(list):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def get_version(package):
author_email='tom@tomchristie.com', # SEE NOTE BELOW (*)
packages=find_packages(exclude=['tests*']),
include_package_data=True,
install_requires=["django>=4.2", 'backports.zoneinfo;python_version<"3.9"'],
install_requires=["django>=4.2"],
python_requires=">=3.9",
zip_safe=False,
classifiers=[
Expand Down
11 changes: 1 addition & 10 deletions tests/test_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
import math
import os
import re
import sys
import uuid
import warnings
from decimal import ROUND_DOWN, ROUND_UP, Decimal
from enum import auto
from unittest.mock import patch
from zoneinfo import ZoneInfo

import pytest

Expand All @@ -30,11 +30,6 @@
)
from tests.models import UUIDForeignKeyTarget

if sys.version_info >= (3, 9):
from zoneinfo import ZoneInfo
else:
from backports.zoneinfo import ZoneInfo

utc = datetime.timezone.utc

# Tests for helper functions.
Expand Down Expand Up @@ -641,10 +636,6 @@ def test_parent_binding(self):


class TestTyping(TestCase):
@pytest.mark.skipif(
sys.version_info < (3, 7),
reason="subscriptable classes requires Python 3.7 or higher",
)
def test_field_is_subscriptable(self):
assert serializers.Field is serializers.Field["foo"]

Expand Down
14 changes: 0 additions & 14 deletions tests/test_generics.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import sys

import pytest
from django.db import models
from django.http import Http404
Expand Down Expand Up @@ -703,23 +701,11 @@ def list(self, request):


class TestTyping(TestCase):
@pytest.mark.skipif(
sys.version_info < (3, 7),
reason="subscriptable classes requires Python 3.7 or higher",
)
def test_genericview_is_subscriptable(self):
assert generics.GenericAPIView is generics.GenericAPIView["foo"]

@pytest.mark.skipif(
sys.version_info < (3, 7),
reason="subscriptable classes requires Python 3.7 or higher",
)
def test_listview_is_subscriptable(self):
assert generics.ListAPIView is generics.ListAPIView["foo"]

@pytest.mark.skipif(
sys.version_info < (3, 7),
reason="subscriptable classes requires Python 3.7 or higher",
)
def test_instanceview_is_subscriptable(self):
assert generics.RetrieveAPIView is generics.RetrieveAPIView["foo"]
5 changes: 0 additions & 5 deletions tests/test_model_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import decimal
import json # noqa
import re
import sys
import tempfile

import pytest
Expand Down Expand Up @@ -397,10 +396,6 @@ class Meta:
fields = '__all__'

expected = dedent("""
TestSerializer():
id = IntegerField(label='ID', read_only=True)
duration_field = DurationField(max_value=datetime.timedelta(3), min_value=datetime.timedelta(1))
""") if sys.version_info < (3, 7) else dedent("""
TestSerializer():
id = IntegerField(label='ID', read_only=True)
duration_field = DurationField(max_value=datetime.timedelta(days=3), min_value=datetime.timedelta(days=1))
Expand Down
5 changes: 0 additions & 5 deletions tests/test_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"""
import copy
import os.path
import sys
import tempfile

import pytest
Expand Down Expand Up @@ -375,9 +374,5 @@ def test_deepcopy_works(self):


class TestTyping(TestCase):
@pytest.mark.skipif(
sys.version_info < (3, 7),
reason="subscriptable classes requires Python 3.7 or higher",
)
def test_request_is_subscriptable(self):
assert Request is Request["foo"]
7 changes: 0 additions & 7 deletions tests/test_response.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import sys

import pytest
from django.test import TestCase, override_settings
from django.urls import include, path, re_path

Expand Down Expand Up @@ -289,9 +286,5 @@ def test_form_has_label_and_help_text(self):


class TestTyping(TestCase):
@pytest.mark.skipif(
sys.version_info < (3, 7),
reason="subscriptable classes requires Python 3.7 or higher",
)
def test_response_is_subscriptable(self):
assert Response is Response["foo"]
9 changes: 0 additions & 9 deletions tests/test_serializer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import inspect
import pickle
import re
import sys
from collections import ChainMap
from collections.abc import Mapping

Expand Down Expand Up @@ -205,10 +204,6 @@ class ExampleSerializer(serializers.Serializer):
exceptions.ErrorDetail(string='Raised error', code='invalid')
]}

@pytest.mark.skipif(
sys.version_info < (3, 7),
reason="subscriptable classes requires Python 3.7 or higher",
)
def test_serializer_is_subscriptable(self):
assert serializers.Serializer is serializers.Serializer["foo"]

Expand Down Expand Up @@ -743,10 +738,6 @@ class TestSerializer(A, B):


class Test8301Regression:
@pytest.mark.skipif(
sys.version_info < (3, 9),
reason="dictionary union operator requires Python 3.9 or higher",
)
def test_ReturnDict_merging(self):
# Serializer.data returns ReturnDict, this is essentially a test for that.

Expand Down
6 changes: 0 additions & 6 deletions tests/test_serializer_lists.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import sys

import pytest
from django.http import QueryDict
from django.utils.datastructures import MultiValueDict
Expand Down Expand Up @@ -60,10 +58,6 @@ def test_validate_html_input(self):
assert serializer.is_valid()
assert serializer.validated_data == expected_output

@pytest.mark.skipif(
sys.version_info < (3, 7),
reason="subscriptable classes requires Python 3.7 or higher",
)
def test_list_serializer_is_subscriptable(self):
assert serializers.ListSerializer is serializers.ListSerializer["foo"]

Expand Down
Loading