From 162175f0c412a72c178fb897224a400f912ad6ff Mon Sep 17 00:00:00 2001 From: Braden MacDonald Date: Mon, 10 Jul 2023 11:16:57 -0700 Subject: [PATCH] chore: get rid of edx_six - not needed anymore (#32555) * chore: get rid of edx_six - not needed anymore * chore: remove reference to TODO that was completed. --- .../contentstore/tests/test_i18n.py | 11 ++-- openedx/core/lib/edx_six.py | 12 ---- xmodule/capa/capa_problem.py | 7 +-- xmodule/capa/inputtypes.py | 29 +++++----- xmodule/capa/responsetypes.py | 58 ++++++++----------- 5 files changed, 46 insertions(+), 71 deletions(-) delete mode 100644 openedx/core/lib/edx_six.py diff --git a/cms/djangoapps/contentstore/tests/test_i18n.py b/cms/djangoapps/contentstore/tests/test_i18n.py index 8f9674fcc3..db0ed7e04d 100644 --- a/cms/djangoapps/contentstore/tests/test_i18n.py +++ b/cms/djangoapps/contentstore/tests/test_i18n.py @@ -1,8 +1,6 @@ """ Tests for validate Internationalization and XBlock i18n service. """ - - import gettext from unittest import mock, skip @@ -17,7 +15,6 @@ from xmodule.tests.test_export import PureXBlock from cms.djangoapps.contentstore.tests.utils import AjaxEnabledTestClient from cms.djangoapps.contentstore.views.preview import _prepare_runtime_for_preview from common.djangoapps.student.tests.factories import UserFactory -from openedx.core.lib.edx_six import get_gettext class FakeTranslations(XBlockI18nService): @@ -94,7 +91,7 @@ class TestXBlockI18nService(ModuleStoreTestCase): def __init__(self, module): self.module = module - self.old_ugettext = get_gettext(module) + self.old_ugettext = module.gettext def __enter__(self): def new_ugettext(*args, **kwargs): @@ -152,9 +149,9 @@ class TestXBlockI18nService(ModuleStoreTestCase): with mock.patch('gettext.translation', return_value=_translator(domain='text', localedir=localedir, languages=[get_language()])): i18n_service = self.get_block_i18n_service(self.block) - self.assertEqual(get_gettext(i18n_service)('Hello'), 'Hello') - self.assertNotEqual(get_gettext(i18n_service)('Hello'), 'fr-hello-world') - self.assertNotEqual(get_gettext(i18n_service)('Hello'), 'es-hello-world') + self.assertEqual(i18n_service.gettext('Hello'), 'Hello') + self.assertNotEqual(i18n_service.gettext('Hello'), 'fr-hello-world') + self.assertNotEqual(i18n_service.gettext('Hello'), 'es-hello-world') translation.activate("fr") with mock.patch('gettext.translation', return_value=_translator(domain='text', localedir=localedir, diff --git a/openedx/core/lib/edx_six.py b/openedx/core/lib/edx_six.py deleted file mode 100644 index 9e6ecaa58c..0000000000 --- a/openedx/core/lib/edx_six.py +++ /dev/null @@ -1,12 +0,0 @@ -""" -Extra methods to do some python 2 to 3 things we need to do in edx-platform. - -This is internal and should not be referenced outside of the edx-platform repo. -""" - - -def get_gettext(o): - """ - In python 2 return the ugettext attribute. In python 3 return gettext. - """ - return o.gettext diff --git a/xmodule/capa/capa_problem.py b/xmodule/capa/capa_problem.py index 9dd17cc253..d8b9b85c7b 100644 --- a/xmodule/capa/capa_problem.py +++ b/xmodule/capa/capa_problem.py @@ -36,7 +36,6 @@ from xmodule.capa.correctmap import CorrectMap from xmodule.capa.safe_exec import safe_exec from xmodule.capa.util import contextualize_text, convert_files_to_filenames, get_course_id_from_capa_block from openedx.core.djangolib.markup import HTML, Text -from openedx.core.lib.edx_six import get_gettext from xmodule.stringify import stringify_children # extra things displayed after "show answers" is pressed @@ -483,7 +482,7 @@ class LoncapaProblem(object): # an earlier submission, so for now skip these entirely. # TODO: figure out where to get file submissions when rescoring. if 'filesubmission' in responder.allowed_inputfields and student_answers is None: - _ = get_gettext(self.capa_system.i18n) + _ = self.capa_system.i18n.gettext raise Exception(_("Cannot rescore problems with possible file submissions")) # use 'student_answers' only if it is provided, and if it might contain a file @@ -580,7 +579,7 @@ class LoncapaProblem(object): question_nr = int(answer_id.split('_')[-2]) - 1 return _("Question {}").format(question_nr) - _ = get_gettext(self.capa_system.i18n) + _ = self.capa_system.i18n.gettext # Some questions define a prompt with this format: >>This is a prompt<< try: prompt = self.problem_data[answer_id].get('label') @@ -693,7 +692,7 @@ class LoncapaProblem(object): choice-level explanations shown to a student after submission. Does nothing if there is no targeted-feedback attribute. """ - _ = get_gettext(self.capa_system.i18n) + _ = self.capa_system.i18n.gettext # Note that the modifications has been done, avoiding problems if called twice. if hasattr(self, 'has_targeted'): return diff --git a/xmodule/capa/inputtypes.py b/xmodule/capa/inputtypes.py index f1817415ca..c3f67bc0b0 100644 --- a/xmodule/capa/inputtypes.py +++ b/xmodule/capa/inputtypes.py @@ -59,7 +59,6 @@ from six import text_type from xmodule.capa.xqueue_interface import XQUEUE_TIMEOUT from openedx.core.djangolib.markup import HTML, Text -from openedx.core.lib import edx_six from xmodule.stringify import stringify_children from . import xqueue_interface @@ -327,7 +326,7 @@ class InputTypeBase(object): context = { 'id': self.input_id, 'value': self.value, - 'status': Status(self.status, edx_six.get_gettext(self.capa_system.i18n)), + 'status': Status(self.status, self.capa_system.i18n.gettext), 'msg': self.msg, 'response_data': self.response_data, 'STATIC_URL': self.capa_system.STATIC_URL, @@ -459,7 +458,7 @@ class OptionInput(InputTypeBase): """ Return extra context. """ - _ = edx_six.get_gettext(self.capa_system.i18n) + _ = self.capa_system.i18n.gettext return {'default_option_text': _('Select an option')} #----------------------------------------------------------------------------- @@ -507,7 +506,7 @@ class ChoiceGroup(InputTypeBase): self.html_input_type = "checkbox" self.suffix = '[]' else: - _ = edx_six.get_gettext(i18n) + _ = i18n.gettext # Translators: 'ChoiceGroup' is an input type and should not be translated. msg = _("ChoiceGroup: unexpected tag {tag_name}").format(tag_name=self.tag) raise Exception(msg) @@ -543,7 +542,7 @@ class ChoiceGroup(InputTypeBase): """ choices = [] - _ = edx_six.get_gettext(i18n) + _ = i18n.gettext for choice in element: if choice.tag == 'choice': @@ -740,7 +739,7 @@ class FileSubmission(InputTypeBase): Do some magic to handle queueing status (render as "queued" instead of "incomplete"), pull queue_len from the msg field. (TODO: get rid of the queue_len hack). """ - _ = edx_six.get_gettext(self.capa_system.i18n) + _ = self.capa_system.i18n.gettext submitted_msg = _("Your files have been submitted. As soon as your submission is" " graded, this message will be replaced with the grader's feedback.") self.submitted_msg = submitted_msg @@ -812,7 +811,7 @@ class CodeInput(InputTypeBase): def setup(self): """ setup this input type """ - _ = edx_six.get_gettext(self.capa_system.i18n) + _ = self.capa_system.i18n.gettext submitted_msg = _("Your answer has been submitted. As soon as your submission is" " graded, this message will be replaced with the grader's feedback.") self.submitted_msg = submitted_msg @@ -823,7 +822,7 @@ class CodeInput(InputTypeBase): """ Define queue_len, arial_label and code mirror exit message context variables """ - _ = edx_six.get_gettext(self.capa_system.i18n) + _ = self.capa_system.i18n.gettext return { 'queue_len': self.queue_len, 'aria_label': _('{programming_language} editor').format( @@ -853,7 +852,7 @@ class MatlabInput(CodeInput): """ Handle matlab-specific parsing """ - _ = edx_six.get_gettext(self.capa_system.i18n) + _ = self.capa_system.i18n.gettext submitted_msg = _("Submitted. As soon as a response is returned, " "this message will be replaced by that feedback.") @@ -936,7 +935,7 @@ class MatlabInput(CodeInput): def _extra_context(self): """ Set up additional context variables""" - _ = edx_six.get_gettext(self.capa_system.i18n) + _ = self.capa_system.i18n.gettext queue_msg = self.queue_msg if len(self.queue_msg) > 0: # An empty string cannot be parsed as XML but is okay to include in the template. @@ -985,7 +984,7 @@ class MatlabInput(CodeInput): dict - 'success' - whether or not we successfully queued this submission - 'message' - message to be rendered in case of error """ - _ = edx_six.get_gettext(self.capa_system.i18n) + _ = self.capa_system.i18n.gettext # only send data if xqueue exists if self.capa_system.xqueue is None: return {'success': False, 'message': _('Cannot connect to the queue')} @@ -1212,7 +1211,7 @@ class ChemicalEquationInput(InputTypeBase): } """ - _ = edx_six.get_gettext(self.capa_system.i18n) + _ = self.capa_system.i18n.gettext result = {'preview': '', 'error': ''} try: @@ -1296,7 +1295,7 @@ class FormulaEquationInput(InputTypeBase): 'request_start' :