From f1f1933ab496685deae8ddc813f4e11e4f2e2966 Mon Sep 17 00:00:00 2001 From: Awais Qureshi Date: Tue, 23 Feb 2021 15:58:46 +0500 Subject: [PATCH] BOM-2374 Run Pyupgrade on edxmako. --- common/djangoapps/edxmako/apps.py | 1 + common/djangoapps/edxmako/backend.py | 2 +- common/djangoapps/edxmako/makoloader.py | 4 ++-- common/djangoapps/edxmako/paths.py | 12 ++++++------ common/djangoapps/edxmako/request_context.py | 2 +- common/djangoapps/edxmako/template.py | 3 +-- common/djangoapps/edxmako/tests.py | 4 ++-- 7 files changed, 14 insertions(+), 14 deletions(-) diff --git a/common/djangoapps/edxmako/apps.py b/common/djangoapps/edxmako/apps.py index 5c2f9fdc1e..4f0f5d7748 100644 --- a/common/djangoapps/edxmako/apps.py +++ b/common/djangoapps/edxmako/apps.py @@ -5,6 +5,7 @@ Configuration for the edxmako Django application. from django.apps import AppConfig from django.conf import settings + from . import add_lookup, clear_lookups diff --git a/common/djangoapps/edxmako/backend.py b/common/djangoapps/edxmako/backend.py index 761cb0c4e4..c37aeb3d20 100644 --- a/common/djangoapps/edxmako/backend.py +++ b/common/djangoapps/edxmako/backend.py @@ -36,7 +36,7 @@ class Mako(BaseEngine): """ params = params.copy() options = params.pop('OPTIONS').copy() - super(Mako, self).__init__(params) # lint-amnesty, pylint: disable=super-with-arguments + super().__init__(params) self.context_processors = options.pop('context_processors', []) self.namespace = options.pop('namespace', 'main') diff --git a/common/djangoapps/edxmako/makoloader.py b/common/djangoapps/edxmako/makoloader.py index 70c5401bed..cf3048dc17 100644 --- a/common/djangoapps/edxmako/makoloader.py +++ b/common/djangoapps/edxmako/makoloader.py @@ -4,7 +4,7 @@ import logging from django.conf import settings from django.core.exceptions import ImproperlyConfigured -from django.template import Engine, engines, TemplateDoesNotExist +from django.template import Engine, TemplateDoesNotExist, engines from django.template.loaders.app_directories import Loader as AppDirectoriesLoader from django.template.loaders.filesystem import Loader as FilesystemLoader @@ -14,7 +14,7 @@ from openedx.core.lib.tempdir import mkdtemp_clean log = logging.getLogger(__name__) -class MakoLoader(object): +class MakoLoader: """ This is a Django loader object which will load the template as a Mako template if the first line is "## mako". It is based off Loader diff --git a/common/djangoapps/edxmako/paths.py b/common/djangoapps/edxmako/paths.py index 6ddf44f35e..3f4aa554ae 100644 --- a/common/djangoapps/edxmako/paths.py +++ b/common/djangoapps/edxmako/paths.py @@ -6,9 +6,9 @@ Set up lookup paths for mako templates. import contextlib import hashlib import os -import six import pkg_resources +import six from django.conf import settings from mako.exceptions import TopLevelLookupException from mako.lookup import TemplateLookup @@ -19,7 +19,7 @@ from openedx.core.lib.cache_utils import request_cached from . import LOOKUP -class TopLevelTemplateURI(six.text_type): +class TopLevelTemplateURI(str): """ A marker class for template URIs used to signal the template lookup infrastructure that the template corresponding to the URI should be looked up straight in the standard edx-platform location instead of trying to locate an @@ -34,7 +34,7 @@ class DynamicTemplateLookup(TemplateLookup): for adding directories progressively. """ def __init__(self, *args, **kwargs): - super(DynamicTemplateLookup, self).__init__(*args, **kwargs) # lint-amnesty, pylint: disable=super-with-arguments + super().__init__(*args, **kwargs) self.__original_module_directory = self.template_args['module_directory'] def __repr__(self): @@ -74,7 +74,7 @@ class DynamicTemplateLookup(TemplateLookup): that template lookup skips the current theme and looks up the built-in template in standard locations. """ # Make requested uri relative to the calling uri. - relative_uri = super(DynamicTemplateLookup, self).adjust_uri(uri, relativeto) # lint-amnesty, pylint: disable=super-with-arguments + relative_uri = super().adjust_uri(uri, relativeto) # Is the calling template (relativeto) which is including or inheriting current template (uri) # located inside a theme? if relativeto != strip_site_theme_templates_path(relativeto): @@ -99,7 +99,7 @@ class DynamicTemplateLookup(TemplateLookup): else: try: # Try to find themed template, i.e. see if current theme overrides the template - template = super(DynamicTemplateLookup, self).get_template(get_template_path_with_theme(uri)) # lint-amnesty, pylint: disable=super-with-arguments + template = super().get_template(get_template_path_with_theme(uri)) except TopLevelLookupException: template = self._get_toplevel_template(uri) @@ -110,7 +110,7 @@ class DynamicTemplateLookup(TemplateLookup): Lookup a default/toplevel template, ignoring current theme. """ # Strip off the prefix path to theme and look in default template dirs. - return super(DynamicTemplateLookup, self).get_template(strip_site_theme_templates_path(uri)) # lint-amnesty, pylint: disable=super-with-arguments + return super().get_template(strip_site_theme_templates_path(uri)) def clear_lookups(namespace): diff --git a/common/djangoapps/edxmako/request_context.py b/common/djangoapps/edxmako/request_context.py index 5be4c1fd47..a276893cf2 100644 --- a/common/djangoapps/edxmako/request_context.py +++ b/common/djangoapps/edxmako/request_context.py @@ -21,8 +21,8 @@ Methods for creating RequestContext for using with Mako templates. from crum import get_current_request from django.template import RequestContext - from edx_django_utils.cache import RequestCache + from openedx.core.lib.request_utils import safe_get_host diff --git a/common/djangoapps/edxmako/template.py b/common/djangoapps/edxmako/template.py index e0ec9c4998..2fde67a055 100644 --- a/common/djangoapps/edxmako/template.py +++ b/common/djangoapps/edxmako/template.py @@ -17,7 +17,6 @@ from django.conf import settings from django.template import Context, engines, Origin from edx_django_utils.cache import RequestCache from mako.template import Template as MakoTemplate -from six import text_type from . import Engines, LOOKUP from .request_context import get_template_request_context @@ -122,4 +121,4 @@ class Template(object): """ for key in KEY_CSRF_TOKENS: if key in context_dictionary: - context_dictionary[key] = text_type(context_dictionary[key]) + context_dictionary[key] = str(context_dictionary[key]) diff --git a/common/djangoapps/edxmako/tests.py b/common/djangoapps/edxmako/tests.py index a64211072d..2e0bf2e48e 100644 --- a/common/djangoapps/edxmako/tests.py +++ b/common/djangoapps/edxmako/tests.py @@ -1,6 +1,7 @@ # lint-amnesty, pylint: disable=cyclic-import, missing-module-docstring import unittest +from unittest.mock import Mock, patch import ddt from django.conf import settings @@ -10,7 +11,6 @@ from django.test.client import RequestFactory from django.test.utils import override_settings from django.urls import reverse from edx_django_utils.cache import RequestCache -from mock import Mock, patch from common.djangoapps.edxmako import LOOKUP, add_lookup from common.djangoapps.edxmako.request_context import get_template_request_context @@ -139,7 +139,7 @@ class MakoRequestContextTest(TestCase): """ def setUp(self): - super(MakoRequestContextTest, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments + super().setUp() self.user = UserFactory.create() self.url = "/" self.request = RequestFactory().get(self.url)