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 Jun 14, 2024
1 parent 1194b90 commit 414973e
Show file tree
Hide file tree
Showing 21 changed files with 813 additions and 568 deletions.
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
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 414973e

Please sign in to comment.