mirror of
				https://github.com/encode/django-rest-framework.git
				synced 2025-10-31 16:07:38 +03:00 
			
		
		
		
	Cleanup dependencies and conditions for unsupported Python versions (#9681)
* Remove optional install backports.zoneinfo for unsupported Python versions and associated code * Remove conditions in tests for unsupported Python versions * Remove condition for unsupported Python versions
This commit is contained in:
		
							parent
							
								
									c41314f1fc
								
							
						
					
					
						commit
						3c755794df
					
				|  | @ -1,5 +1,4 @@ | ||||||
| import contextlib | import contextlib | ||||||
| import sys |  | ||||||
| from collections.abc import Mapping, MutableMapping | from collections.abc import Mapping, MutableMapping | ||||||
| 
 | 
 | ||||||
| from django.utils.encoding import force_str | from django.utils.encoding import force_str | ||||||
|  | @ -29,21 +28,20 @@ class ReturnDict(dict): | ||||||
|         # but preserve the raw data. |         # but preserve the raw data. | ||||||
|         return (dict, (dict(self),)) |         return (dict, (dict(self),)) | ||||||
| 
 | 
 | ||||||
|     if sys.version_info >= (3, 9): |     # These are basically copied from OrderedDict, with `serializer` added. | ||||||
|         # These are basically copied from OrderedDict, with `serializer` added. |     def __or__(self, other): | ||||||
|         def __or__(self, other): |         if not isinstance(other, dict): | ||||||
|             if not isinstance(other, dict): |             return NotImplemented | ||||||
|                 return NotImplemented |         new = self.__class__(self, serializer=self.serializer) | ||||||
|             new = self.__class__(self, serializer=self.serializer) |         new.update(other) | ||||||
|             new.update(other) |         return new | ||||||
|             return new |  | ||||||
| 
 | 
 | ||||||
|         def __ror__(self, other): |     def __ror__(self, other): | ||||||
|             if not isinstance(other, dict): |         if not isinstance(other, dict): | ||||||
|                 return NotImplemented |             return NotImplemented | ||||||
|             new = self.__class__(other, serializer=self.serializer) |         new = self.__class__(other, serializer=self.serializer) | ||||||
|             new.update(self) |         new.update(self) | ||||||
|             return new |         return new | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class ReturnList(list): | class ReturnList(list): | ||||||
|  |  | ||||||
							
								
								
									
										2
									
								
								setup.py
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								setup.py
									
									
									
									
									
								
							|  | @ -81,7 +81,7 @@ setup( | ||||||
|     author_email='tom@tomchristie.com',  # SEE NOTE BELOW (*) |     author_email='tom@tomchristie.com',  # SEE NOTE BELOW (*) | ||||||
|     packages=find_packages(exclude=['tests*']), |     packages=find_packages(exclude=['tests*']), | ||||||
|     include_package_data=True, |     include_package_data=True, | ||||||
|     install_requires=["django>=4.2", 'backports.zoneinfo;python_version<"3.9"'], |     install_requires=["django>=4.2"], | ||||||
|     python_requires=">=3.9", |     python_requires=">=3.9", | ||||||
|     zip_safe=False, |     zip_safe=False, | ||||||
|     classifiers=[ |     classifiers=[ | ||||||
|  |  | ||||||
|  | @ -2,12 +2,12 @@ import datetime | ||||||
| import math | import math | ||||||
| import os | import os | ||||||
| import re | import re | ||||||
| import sys |  | ||||||
| import uuid | import uuid | ||||||
| import warnings | import warnings | ||||||
| from decimal import ROUND_DOWN, ROUND_UP, Decimal | from decimal import ROUND_DOWN, ROUND_UP, Decimal | ||||||
| from enum import auto | from enum import auto | ||||||
| from unittest.mock import patch | from unittest.mock import patch | ||||||
|  | from zoneinfo import ZoneInfo | ||||||
| 
 | 
 | ||||||
| import pytest | import pytest | ||||||
| 
 | 
 | ||||||
|  | @ -30,11 +30,6 @@ from rest_framework.fields import ( | ||||||
| ) | ) | ||||||
| from tests.models import UUIDForeignKeyTarget | 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 | utc = datetime.timezone.utc | ||||||
| 
 | 
 | ||||||
| # Tests for helper functions. | # Tests for helper functions. | ||||||
|  | @ -641,10 +636,6 @@ class Test5087Regression: | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class TestTyping(TestCase): | 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): |     def test_field_is_subscriptable(self): | ||||||
|         assert serializers.Field is serializers.Field["foo"] |         assert serializers.Field is serializers.Field["foo"] | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -1,5 +1,3 @@ | ||||||
| import sys |  | ||||||
| 
 |  | ||||||
| import pytest | import pytest | ||||||
| from django.db import models | from django.db import models | ||||||
| from django.http import Http404 | from django.http import Http404 | ||||||
|  | @ -703,23 +701,11 @@ class TestSerializer(TestCase): | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class TestTyping(TestCase): | 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): |     def test_genericview_is_subscriptable(self): | ||||||
|         assert generics.GenericAPIView is generics.GenericAPIView["foo"] |         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): |     def test_listview_is_subscriptable(self): | ||||||
|         assert generics.ListAPIView is generics.ListAPIView["foo"] |         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): |     def test_instanceview_is_subscriptable(self): | ||||||
|         assert generics.RetrieveAPIView is generics.RetrieveAPIView["foo"] |         assert generics.RetrieveAPIView is generics.RetrieveAPIView["foo"] | ||||||
|  |  | ||||||
|  | @ -9,7 +9,6 @@ import datetime | ||||||
| import decimal | import decimal | ||||||
| import json  # noqa | import json  # noqa | ||||||
| import re | import re | ||||||
| import sys |  | ||||||
| import tempfile | import tempfile | ||||||
| 
 | 
 | ||||||
| import pytest | import pytest | ||||||
|  | @ -397,10 +396,6 @@ class TestDurationFieldMapping(TestCase): | ||||||
|                 fields = '__all__' |                 fields = '__all__' | ||||||
| 
 | 
 | ||||||
|         expected = dedent(""" |         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(): |             TestSerializer(): | ||||||
|                 id = IntegerField(label='ID', read_only=True) |                 id = IntegerField(label='ID', read_only=True) | ||||||
|                 duration_field = DurationField(max_value=datetime.timedelta(days=3), min_value=datetime.timedelta(days=1)) |                 duration_field = DurationField(max_value=datetime.timedelta(days=3), min_value=datetime.timedelta(days=1)) | ||||||
|  |  | ||||||
|  | @ -3,7 +3,6 @@ Tests for content parsing, and form-overloaded content parsing. | ||||||
| """ | """ | ||||||
| import copy | import copy | ||||||
| import os.path | import os.path | ||||||
| import sys |  | ||||||
| import tempfile | import tempfile | ||||||
| 
 | 
 | ||||||
| import pytest | import pytest | ||||||
|  | @ -375,9 +374,5 @@ class TestDeepcopy(TestCase): | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class TestTyping(TestCase): | 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): |     def test_request_is_subscriptable(self): | ||||||
|         assert Request is Request["foo"] |         assert Request is Request["foo"] | ||||||
|  |  | ||||||
|  | @ -1,6 +1,3 @@ | ||||||
| import sys |  | ||||||
| 
 |  | ||||||
| import pytest |  | ||||||
| from django.test import TestCase, override_settings | from django.test import TestCase, override_settings | ||||||
| from django.urls import include, path, re_path | from django.urls import include, path, re_path | ||||||
| 
 | 
 | ||||||
|  | @ -289,9 +286,5 @@ class Issue807Tests(TestCase): | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class TestTyping(TestCase): | 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): |     def test_response_is_subscriptable(self): | ||||||
|         assert Response is Response["foo"] |         assert Response is Response["foo"] | ||||||
|  |  | ||||||
|  | @ -1,7 +1,6 @@ | ||||||
| import inspect | import inspect | ||||||
| import pickle | import pickle | ||||||
| import re | import re | ||||||
| import sys |  | ||||||
| from collections import ChainMap | from collections import ChainMap | ||||||
| from collections.abc import Mapping | from collections.abc import Mapping | ||||||
| 
 | 
 | ||||||
|  | @ -205,10 +204,6 @@ class TestSerializer: | ||||||
|                 exceptions.ErrorDetail(string='Raised error', code='invalid') |                 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): |     def test_serializer_is_subscriptable(self): | ||||||
|         assert serializers.Serializer is serializers.Serializer["foo"] |         assert serializers.Serializer is serializers.Serializer["foo"] | ||||||
| 
 | 
 | ||||||
|  | @ -743,10 +738,6 @@ class TestDeclaredFieldInheritance: | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class Test8301Regression: | 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): |     def test_ReturnDict_merging(self): | ||||||
|         # Serializer.data returns ReturnDict, this is essentially a test for that. |         # Serializer.data returns ReturnDict, this is essentially a test for that. | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -1,5 +1,3 @@ | ||||||
| import sys |  | ||||||
| 
 |  | ||||||
| import pytest | import pytest | ||||||
| from django.http import QueryDict | from django.http import QueryDict | ||||||
| from django.utils.datastructures import MultiValueDict | from django.utils.datastructures import MultiValueDict | ||||||
|  | @ -60,10 +58,6 @@ class TestListSerializer: | ||||||
|         assert serializer.is_valid() |         assert serializer.is_valid() | ||||||
|         assert serializer.validated_data == expected_output |         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): |     def test_list_serializer_is_subscriptable(self): | ||||||
|         assert serializers.ListSerializer is serializers.ListSerializer["foo"] |         assert serializers.ListSerializer is serializers.ListSerializer["foo"] | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user