Skip to content

Commit

Permalink
feat!: annotate types
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kdmccormick committed Aug 20, 2024
1 parent 2d8e5f1 commit 0dbf212
Show file tree
Hide file tree
Showing 23 changed files with 854 additions and 588 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ Change history for XBlock
Unreleased
----------

6.0.0 - 2024-08-20
------------------

* added type hints to all public classes, methods, and functions

5.1.0 - 2024-08-07
------------------

* added ability to override an XBlock with the 'xblock.v1.overrides' entry point
* added ability to override an XBlock Aside with the 'xblock_asides.v1.overrides' entry point


5.0.0 - 2024-05-30
------------------

Expand Down
2 changes: 2 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ ignore_missing_imports = False
allow_untyped_globals = False
files =
xblock
exclude =
xblock.test

# Ignore web_fragments typing until it has hints.
[mypy-web_fragments.*]
Expand Down
2 changes: 1 addition & 1 deletion xblock/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
XBlock Courseware Components
"""

__version__ = '5.1.0'
__version__ = '6.0.0'
11 changes: 6 additions & 5 deletions xblock/completable.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
This module defines CompletableXBlockMixin and completion mode enumeration.
"""
from xblock.core import Blocklike, XBlockMixin


class XBlockCompletionMode:
Expand All @@ -12,7 +13,7 @@ class XBlockCompletionMode:
EXCLUDED = "excluded"

@classmethod
def get_mode(cls, block_class):
def get_mode(cls, block_class: Blocklike | type[Blocklike]) -> str:
"""
Return the effective completion mode for a given block.
Expand All @@ -21,17 +22,17 @@ def get_mode(cls, block_class):
return getattr(block_class, 'completion_mode', cls.COMPLETABLE)


class CompletableXBlockMixin:
class CompletableXBlockMixin(XBlockMixin):
"""
This mixin sets attributes and provides helper method to integrate XBlock with Completion API.
"""

has_custom_completion = True
completion_mode = XBlockCompletionMode.COMPLETABLE
has_custom_completion: bool = True
completion_mode: str = XBlockCompletionMode.COMPLETABLE

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

0 comments on commit 0dbf212

Please sign in to comment.