Skip to content

Commit de92e7a

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 5bf829e commit de92e7a

23 files changed

+847
-584
lines changed

CHANGELOG.rst

+6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ Change history for XBlock
55
Unreleased
66
----------
77

8+
6.0.0 - 2024-08-05
9+
------------------
10+
11+
* added type hints to all public classes, methods, and functions
12+
13+
814
5.0.0 - 2024-05-30
915
------------------
1016

mypy.ini

+2
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/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
XBlock Courseware Components
33
"""
44

5-
__version__ = '5.0.0'
5+
__version__ = '6.0.0'

xblock/completable.py

+6-5
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)