Skip to content

Commit 414973e

Browse files
committed
feat!: annotate types
BREAKING CHANGE: [Developers only] Type-checked Python code using the XBlock API will likely need to be updated in order to continue passing type-checking, since XBlock's new annotations will trigger mypy (et al) to behave much more strictly. NO BREAKING CHANGES for site operators, authors, learners, etc.
1 parent 1194b90 commit 414973e

21 files changed

+813
-568
lines changed

mypy.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ ignore_missing_imports = False
44
allow_untyped_globals = False
55
files =
66
xblock
7+
exclude =
8+
xblock.test
79

810
# Ignore web_fragments typing until it has hints.
911
[mypy-web_fragments.*]

xblock/completable.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
This module defines CompletableXBlockMixin and completion mode enumeration.
33
"""
4+
from xblock.core import Blocklike, XBlockMixin
45

56

67
class XBlockCompletionMode:
@@ -12,7 +13,7 @@ class XBlockCompletionMode:
1213
EXCLUDED = "excluded"
1314

1415
@classmethod
15-
def get_mode(cls, block_class):
16+
def get_mode(cls, block_class: Blocklike | type[Blocklike]) -> str:
1617
"""
1718
Return the effective completion mode for a given block.
1819
@@ -21,17 +22,17 @@ def get_mode(cls, block_class):
2122
return getattr(block_class, 'completion_mode', cls.COMPLETABLE)
2223

2324

24-
class CompletableXBlockMixin:
25+
class CompletableXBlockMixin(XBlockMixin):
2526
"""
2627
This mixin sets attributes and provides helper method to integrate XBlock with Completion API.
2728
"""
2829

29-
has_custom_completion = True
30-
completion_mode = XBlockCompletionMode.COMPLETABLE
30+
has_custom_completion: bool = True
31+
completion_mode: str = XBlockCompletionMode.COMPLETABLE
3132

3233
# To read more on the debate about using the terms percent vs ratio, see:
3334
# https://openedx.atlassian.net/wiki/spaces/OpenDev/pages/245465398/Naming+with+Percent+or+Ratio
34-
def emit_completion(self, completion_percent):
35+
def emit_completion(self, completion_percent: float) -> None:
3536
"""
3637
Emits completion event through Completion API.
3738

0 commit comments

Comments
 (0)