From c169b296bd0e83b02d3689e04d50e4d76722d239 Mon Sep 17 00:00:00 2001 From: David Cain Date: Sat, 21 Aug 2021 16:08:43 -0700 Subject: [PATCH 1/2] Delete no-op imports from `__future__` Version 2.3 officially dropped support for Python 2.7 (which reached its end of life at the end of 2020). In Python 3, all string literals are Unicode. Expressly stating file encoding is no longer necessary (files now default to being interpreted as UTF-8 instead of ASCII), but it's somewhat harmless. --- examples/server/forms/client_validation.py | 1 - examples/server/forms/combined_validation.py | 1 - examples/server/forms/forms_set.py | 1 - examples/server/forms/image_file_upload.py | 1 - examples/server/forms/model_scope.py | 1 - examples/server/forms/subscribe_form.py | 1 - examples/server/models/image_file_upload.py | 1 - examples/server/settings.py | 1 - examples/server/templatetags/tutorial_tags.py | 1 - examples/server/tests/settings.py | 1 - examples/server/tests/test_fileupload.py | 2 -- examples/server/tests/test_postprocessor.py | 2 -- examples/server/tests/test_templatetags.py | 2 -- examples/server/views/classic_subscribe.py | 1 - examples/server/views/forms_set.py | 1 - 15 files changed, 18 deletions(-) diff --git a/examples/server/forms/client_validation.py b/examples/server/forms/client_validation.py index 110a50f..0b88dcd 100644 --- a/examples/server/forms/client_validation.py +++ b/examples/server/forms/client_validation.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- -from __future__ import unicode_literals # start tutorial from django.forms import widgets from django.core.exceptions import ValidationError diff --git a/examples/server/forms/combined_validation.py b/examples/server/forms/combined_validation.py index e7d55f2..f3f5e99 100644 --- a/examples/server/forms/combined_validation.py +++ b/examples/server/forms/combined_validation.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- -from __future__ import unicode_literals # start tutorial from django.core.exceptions import ValidationError from django.forms import widgets diff --git a/examples/server/forms/forms_set.py b/examples/server/forms/forms_set.py index 9130eac..7e87e9a 100644 --- a/examples/server/forms/forms_set.py +++ b/examples/server/forms/forms_set.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- -from __future__ import unicode_literals # start tutorial import re from django.core.exceptions import ValidationError diff --git a/examples/server/forms/image_file_upload.py b/examples/server/forms/image_file_upload.py index 78b2423..862e2c2 100644 --- a/examples/server/forms/image_file_upload.py +++ b/examples/server/forms/image_file_upload.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- -from __future__ import unicode_literals # start tutorial from djng.forms import fields, NgModelFormMixin, NgFormValidationMixin from djng.styling.bootstrap3.forms import Bootstrap3Form diff --git a/examples/server/forms/model_scope.py b/examples/server/forms/model_scope.py index c45638c..66ba447 100644 --- a/examples/server/forms/model_scope.py +++ b/examples/server/forms/model_scope.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- -from __future__ import unicode_literals # start tutorial from django.core.exceptions import ValidationError from django.forms import widgets diff --git a/examples/server/forms/subscribe_form.py b/examples/server/forms/subscribe_form.py index 2cb8a19..cd183af 100644 --- a/examples/server/forms/subscribe_form.py +++ b/examples/server/forms/subscribe_form.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- -from __future__ import unicode_literals # start tutorial from django.forms import widgets from django.core.exceptions import ValidationError diff --git a/examples/server/models/image_file_upload.py b/examples/server/models/image_file_upload.py index 86b4af0..d3fd19a 100644 --- a/examples/server/models/image_file_upload.py +++ b/examples/server/models/image_file_upload.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- -from __future__ import unicode_literals # start tutorial from django.db import models from djng.forms import NgModelFormMixin, NgFormValidationMixin diff --git a/examples/server/settings.py b/examples/server/settings.py index 295faea..2c99cf2 100644 --- a/examples/server/settings.py +++ b/examples/server/settings.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- -from __future__ import unicode_literals # Django settings for unit test project. import os diff --git a/examples/server/templatetags/tutorial_tags.py b/examples/server/templatetags/tutorial_tags.py index 402fa95..b9257b4 100644 --- a/examples/server/templatetags/tutorial_tags.py +++ b/examples/server/templatetags/tutorial_tags.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- -from __future__ import unicode_literals import os from django import template from django.conf import settings diff --git a/examples/server/tests/settings.py b/examples/server/tests/settings.py index 311cccb..8345bc6 100644 --- a/examples/server/tests/settings.py +++ b/examples/server/tests/settings.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- -from __future__ import unicode_literals """Django settings for unit test project.""" import os diff --git a/examples/server/tests/test_fileupload.py b/examples/server/tests/test_fileupload.py index 5e7f832..f530b4a 100644 --- a/examples/server/tests/test_fileupload.py +++ b/examples/server/tests/test_fileupload.py @@ -1,6 +1,4 @@ # -*- coding: utf-8 -*- -from __future__ import unicode_literals - import os, json from django.conf import settings diff --git a/examples/server/tests/test_postprocessor.py b/examples/server/tests/test_postprocessor.py index e0b46f0..c128b5a 100644 --- a/examples/server/tests/test_postprocessor.py +++ b/examples/server/tests/test_postprocessor.py @@ -1,6 +1,4 @@ # -*- coding: utf-8 -*- -from __future__ import unicode_literals - from django import template from django.test import TestCase from sekizai.context import SekizaiContext diff --git a/examples/server/tests/test_templatetags.py b/examples/server/tests/test_templatetags.py index 10ef79f..43fc4ea 100644 --- a/examples/server/tests/test_templatetags.py +++ b/examples/server/tests/test_templatetags.py @@ -1,6 +1,4 @@ # -*- coding: utf-8 -*- -from __future__ import unicode_literals - from django.test import override_settings, TestCase from django.test.client import Client diff --git a/examples/server/views/classic_subscribe.py b/examples/server/views/classic_subscribe.py index ea027a7..260473f 100644 --- a/examples/server/views/classic_subscribe.py +++ b/examples/server/views/classic_subscribe.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- -from __future__ import unicode_literals from server.forms.subscribe_form import SubscribeForm # start tutorial from django.views.generic.edit import FormView diff --git a/examples/server/views/forms_set.py b/examples/server/views/forms_set.py index 02d5ebc..c82f429 100644 --- a/examples/server/views/forms_set.py +++ b/examples/server/views/forms_set.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- -from __future__ import unicode_literals from server.forms.forms_set import SubscribeForm, AddressForm # start tutorial import json From 9567a6115095fa6aa0cf48193e3d91c3e2acf18a Mon Sep 17 00:00:00 2001 From: David Cain Date: Sat, 21 Aug 2021 16:13:06 -0700 Subject: [PATCH 2/2] Drop the (now meaningless) u prefix from strings In Python 2, strings which made use of Unicode characters would be prefixed with `u`. In Python 3, this prefix is a no-op. We can safely remove it. --- djng/middleware.py | 2 +- examples/server/tests/test_urlresolver_view.py | 2 +- examples/server/tests/test_urlresolvers.py | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/djng/middleware.py b/djng/middleware.py index 6870fe6..7eb74a9 100644 --- a/djng/middleware.py +++ b/djng/middleware.py @@ -31,7 +31,7 @@ def process_request(self, request): If it's not replaced we want to reverse to url we get a request to url '/angular/reverse/?djng_url_name=orders&djng_url_kwarg_id=' which - gives a request.GET QueryDict {u'djng_url_name': [u'orders'], u'djng_url_kwarg_id': [u'']} + gives a request.GET QueryDict {'djng_url_name': ['orders'], 'djng_url_kwarg_id': ['']} In that case we want to ignore the id param and only reverse to url with name 'orders' and no params. So we ignore args and kwargs that are empty strings. diff --git a/examples/server/tests/test_urlresolver_view.py b/examples/server/tests/test_urlresolver_view.py index c130f71..7a5ab04 100644 --- a/examples/server/tests/test_urlresolver_view.py +++ b/examples/server/tests/test_urlresolver_view.py @@ -124,7 +124,7 @@ def test_get_args_with_encoding(self): if six.PY3: args = {'params': 'åäö'} else: - args = {'param': u'åäö'} + args = {'param': 'åäö'} data = { self.url_name_arg: 'home_args', self.args_prefix: [1, 2, 3], diff --git a/examples/server/tests/test_urlresolvers.py b/examples/server/tests/test_urlresolvers.py index d97b8ed..5a3501f 100644 --- a/examples/server/tests/test_urlresolvers.py +++ b/examples/server/tests/test_urlresolvers.py @@ -30,10 +30,10 @@ def test_get_current_remote_methods(self): def test_get_all_remote_methods(self): remote_methods = get_all_remote_methods() expected = { - 'urlresolvertags': {'blah': {u'url': '/url_resolvers/', u'headers': {u'DjNg-Remote-Method': 'blah'}, u'method': 'auto'}}, + 'urlresolvertags': {'blah': {'url': '/url_resolvers/', 'headers': {'DjNg-Remote-Method': 'blah'}, 'method': 'auto'}}, 'submethods': { - 'app': {'foo': {u'url': '/sub_methods/sub/app/', u'headers': {u'DjNg-Remote-Method': 'foo'}, u'method': 'auto'}, - 'bar': {u'url': '/sub_methods/sub/app/', u'headers': {u'DjNg-Remote-Method': 'bar'}, u'method': 'auto'}}, + 'app': {'foo': {'url': '/sub_methods/sub/app/', 'headers': {'DjNg-Remote-Method': 'foo'}, 'method': 'auto'}, + 'bar': {'url': '/sub_methods/sub/app/', 'headers': {'DjNg-Remote-Method': 'bar'}, 'method': 'auto'}}, }, } self.assertDictEqual(remote_methods, expected)