From 3cb9afe6cf464510e6e40b7f03b538810f52f5f9 Mon Sep 17 00:00:00 2001 From: "Kyle D. McCormick" Date: Tue, 20 Aug 2024 12:36:54 -0400 Subject: [PATCH] refactor: make XModuleMixin extend XBlockMixin, not XBlock In order to get typechecking to pass in XBlock, we needed to make ScorableXBlockMixin a subclass of XBlockMixin. This change, while sensible, creates an ambiguous method resolution order in the ProblemBlock, stemming from the fact that XModuleMixin inherits directly from XBlock. The fix is to simply make XModuleMixin inherit from XBlockMixin instead-- this makes sense because XModuleMixin is a helper mixin, not an XBlock itself. We then must add XBlock as an explicit subclass to all blocks which inherit from XBlock. This should have no functional impact, but *should* help us add type hints to the xmodule/ folder in the future. Using ProblemBlock as an example... before (XBlock < 6.0.0) we have: ProblemBlock <- ScorableXBlockMixin <- XModuleMixin <- XBlock <- Blocklike after (XBlock >= 6.0.0) we have: ProblemBlock <- ScorableXBlockMixin <- XBlockMixin <- Blocklike <- XModuleMixin <- XBlockMixin <- Blocklike <- XBlock <- Blocklike --- xmodule/annotatable_block.py | 1 + xmodule/capa_block.py | 1 + xmodule/conditional_block.py | 1 + xmodule/error_block.py | 1 + xmodule/hidden_block.py | 1 + xmodule/html_block.py | 8 ++++---- xmodule/library_content_block.py | 1 + xmodule/lti_block.py | 1 + xmodule/poll_block.py | 1 + xmodule/randomize_block.py | 2 ++ xmodule/seq_block.py | 1 + xmodule/split_test_block.py | 1 + xmodule/template_block.py | 2 ++ xmodule/video_block/video_block.py | 3 ++- xmodule/word_cloud_block.py | 1 + xmodule/x_module.py | 10 +++++----- 16 files changed, 26 insertions(+), 10 deletions(-) diff --git a/xmodule/annotatable_block.py b/xmodule/annotatable_block.py index e41e2b17a52..2394d43418b 100644 --- a/xmodule/annotatable_block.py +++ b/xmodule/annotatable_block.py @@ -35,6 +35,7 @@ class AnnotatableBlock( XModuleToXBlockMixin, ResourceTemplates, XModuleMixin, + XBlock, ): """ Annotatable XBlock. diff --git a/xmodule/capa_block.py b/xmodule/capa_block.py index 54ca0cbc312..d18cf1256b9 100644 --- a/xmodule/capa_block.py +++ b/xmodule/capa_block.py @@ -142,6 +142,7 @@ class ProblemBlock( XModuleToXBlockMixin, ResourceTemplates, XModuleMixin, + XBlock, ): """ An XBlock representing a "problem". diff --git a/xmodule/conditional_block.py b/xmodule/conditional_block.py index 78a5b8c1c1c..d7fe688b22c 100644 --- a/xmodule/conditional_block.py +++ b/xmodule/conditional_block.py @@ -45,6 +45,7 @@ class ConditionalBlock( ResourceTemplates, XModuleMixin, StudioEditableBlock, + XBlock, ): """ Blocks child blocks from showing unless certain conditions are met. diff --git a/xmodule/error_block.py b/xmodule/error_block.py index a3620be8768..355181b14b7 100644 --- a/xmodule/error_block.py +++ b/xmodule/error_block.py @@ -48,6 +48,7 @@ class ErrorBlock( XModuleToXBlockMixin, ResourceTemplates, XModuleMixin, + XBlock, ): # pylint: disable=abstract-method """ Block that gets shown to staff when there has been an error while diff --git a/xmodule/hidden_block.py b/xmodule/hidden_block.py index 0d5c288d75c..8f786d78d49 100644 --- a/xmodule/hidden_block.py +++ b/xmodule/hidden_block.py @@ -18,6 +18,7 @@ class HiddenBlock( XmlMixin, XModuleToXBlockMixin, XModuleMixin, + XBlock, ): """ XBlock class loaded by the runtime when another XBlock type has been disabled diff --git a/xmodule/html_block.py b/xmodule/html_block.py index 2db19836010..46fa7b980d7 100644 --- a/xmodule/html_block.py +++ b/xmodule/html_block.py @@ -353,7 +353,7 @@ def index_dictionary(self): @edxnotes -class HtmlBlock(HtmlBlockMixin): # lint-amnesty, pylint: disable=abstract-method +class HtmlBlock(HtmlBlockMixin, XBlock): # lint-amnesty, pylint: disable=abstract-method """ This is the actual HTML XBlock. Nothing extra is required; this is just a wrapper to include edxnotes support. @@ -374,7 +374,7 @@ class AboutFields: # lint-amnesty, pylint: disable=missing-class-docstring @XBlock.tag("detached") -class AboutBlock(AboutFields, HtmlBlockMixin): # lint-amnesty, pylint: disable=abstract-method +class AboutBlock(AboutFields, HtmlBlockMixin, XBlock): # lint-amnesty, pylint: disable=abstract-method """ These pieces of course content are treated as HtmlBlocks but we need to overload where the templates are located in order to be able to create new ones @@ -409,7 +409,7 @@ class StaticTabFields: @XBlock.tag("detached") -class StaticTabBlock(StaticTabFields, HtmlBlockMixin): # lint-amnesty, pylint: disable=abstract-method +class StaticTabBlock(StaticTabFields, HtmlBlockMixin, XBlock): # lint-amnesty, pylint: disable=abstract-method """ These pieces of course content are treated as HtmlBlocks but we need to overload where the templates are located in order to be able to create new ones @@ -435,7 +435,7 @@ class CourseInfoFields: @XBlock.tag("detached") @XBlock.needs('replace_urls') -class CourseInfoBlock(CourseInfoFields, HtmlBlockMixin): # lint-amnesty, pylint: disable=abstract-method +class CourseInfoBlock(CourseInfoFields, HtmlBlockMixin, XBlock): # lint-amnesty, pylint: disable=abstract-method """ These pieces of course content are treated as HtmlBlock but we need to overload where the templates are located in order to be able to create new ones diff --git a/xmodule/library_content_block.py b/xmodule/library_content_block.py index 09a5d1dee13..cf3dac77d48 100644 --- a/xmodule/library_content_block.py +++ b/xmodule/library_content_block.py @@ -85,6 +85,7 @@ class LibraryContentBlock( ResourceTemplates, XModuleMixin, StudioEditableBlock, + XBlock, ): """ An XBlock whose children are chosen dynamically from a content library. diff --git a/xmodule/lti_block.py b/xmodule/lti_block.py index 55f940b381c..23e8a4f6826 100644 --- a/xmodule/lti_block.py +++ b/xmodule/lti_block.py @@ -284,6 +284,7 @@ class LTIBlock( XModuleToXBlockMixin, ResourceTemplates, XModuleMixin, + XBlock, ): # pylint: disable=abstract-method """ THIS MODULE IS DEPRECATED IN FAVOR OF https://github.com/openedx/xblock-lti-consumer diff --git a/xmodule/poll_block.py b/xmodule/poll_block.py index f09889f506e..eea665d4d52 100644 --- a/xmodule/poll_block.py +++ b/xmodule/poll_block.py @@ -42,6 +42,7 @@ class PollBlock( XModuleToXBlockMixin, ResourceTemplates, XModuleMixin, + XBlock, ): # pylint: disable=abstract-method """Poll Block""" # Name of poll to use in links to this poll diff --git a/xmodule/randomize_block.py b/xmodule/randomize_block.py index b8a1432ff31..b3e5ba682a1 100644 --- a/xmodule/randomize_block.py +++ b/xmodule/randomize_block.py @@ -6,6 +6,7 @@ from django.utils.functional import cached_property from lxml import etree from web_fragments.fragment import Fragment +from xblock.core import XBlock from xblock.fields import Integer, Scope from xmodule.mako_block import MakoTemplateBlockBase from xmodule.seq_block import SequenceMixin @@ -27,6 +28,7 @@ class RandomizeBlock( XModuleToXBlockMixin, ResourceTemplates, XModuleMixin, + XBlock, ): """ Chooses a random child xblock. Chooses the same one every time for each student. diff --git a/xmodule/seq_block.py b/xmodule/seq_block.py index 6d1a8c59ade..f616b891a8e 100644 --- a/xmodule/seq_block.py +++ b/xmodule/seq_block.py @@ -254,6 +254,7 @@ class SequenceBlock( XModuleToXBlockMixin, ResourceTemplates, XModuleMixin, + XBlock, ): """ Layout module which lays out content in a temporal sequence diff --git a/xmodule/split_test_block.py b/xmodule/split_test_block.py index 05ca3a5db45..dcc8ac92733 100644 --- a/xmodule/split_test_block.py +++ b/xmodule/split_test_block.py @@ -134,6 +134,7 @@ class SplitTestBlock( # lint-amnesty, pylint: disable=abstract-method ResourceTemplates, XModuleMixin, StudioEditableBlock, + XBlock, ): """ Show the user the appropriate child. Uses the ExperimentState diff --git a/xmodule/template_block.py b/xmodule/template_block.py index e6e69742cfb..6fbb9e52659 100644 --- a/xmodule/template_block.py +++ b/xmodule/template_block.py @@ -28,6 +28,7 @@ class CustomTagTemplateBlock( # pylint: disable=abstract-method XModuleToXBlockMixin, ResourceTemplates, XModuleMixin, + XBlock, ): """ A block which provides templates for CustomTagBlock. The template name @@ -122,6 +123,7 @@ def export_to_file(self): class TranslateCustomTagBlock( # pylint: disable=abstract-method XModuleToXBlockMixin, XModuleMixin, + XBlock, ): """ Converts olx of the form `<$custom_tag attr="" attr=""/>` to CustomTagBlock diff --git a/xmodule/video_block/video_block.py b/xmodule/video_block/video_block.py index b4fddb63fa7..89080302568 100644 --- a/xmodule/video_block/video_block.py +++ b/xmodule/video_block/video_block.py @@ -122,7 +122,8 @@ class VideoBlock( VideoFields, VideoTranscriptsMixin, VideoStudioViewHandlers, VideoStudentViewHandlers, EmptyDataRawMixin, XmlMixin, EditingMixin, XModuleToXBlockMixin, - ResourceTemplates, XModuleMixin, LicenseMixin): + ResourceTemplates, XModuleMixin, LicenseMixin, + XBlock): """ XML source example: