Skip to content

Commit 6c766c7

Browse files
committed
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
1 parent 651b624 commit 6c766c7

17 files changed

Lines changed: 29 additions & 12 deletions

xmodule/annotatable_block.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class AnnotatableBlock(
3535
XModuleToXBlockMixin,
3636
ResourceTemplates,
3737
XModuleMixin,
38+
XBlock,
3839
):
3940
"""
4041
Annotatable XBlock.

xmodule/capa_block.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ class ProblemBlock(
142142
XModuleToXBlockMixin,
143143
ResourceTemplates,
144144
XModuleMixin,
145+
XBlock,
145146
):
146147
"""
147148
An XBlock representing a "problem".

xmodule/conditional_block.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class ConditionalBlock(
4545
ResourceTemplates,
4646
XModuleMixin,
4747
StudioEditableBlock,
48+
XBlock,
4849
):
4950
"""
5051
Blocks child blocks from showing unless certain conditions are met.

xmodule/error_block.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class ErrorBlock(
4848
XModuleToXBlockMixin,
4949
ResourceTemplates,
5050
XModuleMixin,
51+
XBlock,
5152
): # pylint: disable=abstract-method
5253
"""
5354
Block that gets shown to staff when there has been an error while

xmodule/hidden_block.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class HiddenBlock(
1818
XmlMixin,
1919
XModuleToXBlockMixin,
2020
XModuleMixin,
21+
XBlock,
2122
):
2223
"""
2324
XBlock class loaded by the runtime when another XBlock type has been disabled

xmodule/html_block.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ def index_dictionary(self):
353353

354354

355355
@edxnotes
356-
class HtmlBlock(HtmlBlockMixin): # lint-amnesty, pylint: disable=abstract-method
356+
class HtmlBlock(HtmlBlockMixin, XBlock): # lint-amnesty, pylint: disable=abstract-method
357357
"""
358358
This is the actual HTML XBlock.
359359
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
374374

375375

376376
@XBlock.tag("detached")
377-
class AboutBlock(AboutFields, HtmlBlockMixin): # lint-amnesty, pylint: disable=abstract-method
377+
class AboutBlock(AboutFields, HtmlBlockMixin, XBlock): # lint-amnesty, pylint: disable=abstract-method
378378
"""
379379
These pieces of course content are treated as HtmlBlocks but we need to overload where the templates are located
380380
in order to be able to create new ones
@@ -409,7 +409,7 @@ class StaticTabFields:
409409

410410

411411
@XBlock.tag("detached")
412-
class StaticTabBlock(StaticTabFields, HtmlBlockMixin): # lint-amnesty, pylint: disable=abstract-method
412+
class StaticTabBlock(StaticTabFields, HtmlBlockMixin, XBlock): # lint-amnesty, pylint: disable=abstract-method
413413
"""
414414
These pieces of course content are treated as HtmlBlocks but we need to overload where the templates are located
415415
in order to be able to create new ones
@@ -435,7 +435,7 @@ class CourseInfoFields:
435435

436436
@XBlock.tag("detached")
437437
@XBlock.needs('replace_urls')
438-
class CourseInfoBlock(CourseInfoFields, HtmlBlockMixin): # lint-amnesty, pylint: disable=abstract-method
438+
class CourseInfoBlock(CourseInfoFields, HtmlBlockMixin, XBlock): # lint-amnesty, pylint: disable=abstract-method
439439
"""
440440
These pieces of course content are treated as HtmlBlock but we need to overload where the templates are located
441441
in order to be able to create new ones

xmodule/library_content_block.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ class LibraryContentBlock(
8585
ResourceTemplates,
8686
XModuleMixin,
8787
StudioEditableBlock,
88+
XBlock,
8889
):
8990
"""
9091
An XBlock whose children are chosen dynamically from a content library.

xmodule/lti_block.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ class LTIBlock(
284284
XModuleToXBlockMixin,
285285
ResourceTemplates,
286286
XModuleMixin,
287+
XBlock,
287288
): # pylint: disable=abstract-method
288289
"""
289290
THIS MODULE IS DEPRECATED IN FAVOR OF https://github.com/openedx/xblock-lti-consumer

xmodule/poll_block.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class PollBlock(
4242
XModuleToXBlockMixin,
4343
ResourceTemplates,
4444
XModuleMixin,
45+
XBlock,
4546
): # pylint: disable=abstract-method
4647
"""Poll Block"""
4748
# Name of poll to use in links to this poll

xmodule/randomize_block.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from django.utils.functional import cached_property
77
from lxml import etree
88
from web_fragments.fragment import Fragment
9+
from xblock.core import XBlock
910
from xblock.fields import Integer, Scope
1011
from xmodule.mako_block import MakoTemplateBlockBase
1112
from xmodule.seq_block import SequenceMixin
@@ -27,6 +28,7 @@ class RandomizeBlock(
2728
XModuleToXBlockMixin,
2829
ResourceTemplates,
2930
XModuleMixin,
31+
XBlock,
3032
):
3133
"""
3234
Chooses a random child xblock. Chooses the same one every time for each student.

0 commit comments

Comments
 (0)