Merge pull request #387 from agentydragon/classmethods

Use @classmethod on methods that do not depends on instance state
This commit is contained in:
Damien Elmes 2019-12-26 07:52:51 +10:00 committed by GitHub
commit 49a2bd52f0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -200,12 +200,13 @@ class Template:
return "{unknown field %s}" % tag_name return "{unknown field %s}" % tag_name
return txt return txt
def clozeText(self, txt, ord, type) -> str: @classmethod
def clozeText(cls, txt, ord, type) -> str:
reg = clozeReg reg = clozeReg
if not re.search(reg % ord, txt): if not re.search(reg % ord, txt):
# No Cloze deletion was found in txt. # No Cloze deletion was found in txt.
return "" return ""
txt = self._removeFormattingFromMathjax(txt, ord) txt = cls._removeFormattingFromMathjax(txt, ord)
def repl(m): def repl(m):
# replace chosen cloze with type # replace chosen cloze with type
@ -225,7 +226,8 @@ class Template:
# and display other clozes normally # and display other clozes normally
return re.sub(reg % r"\d+", "\\2", txt) return re.sub(reg % r"\d+", "\\2", txt)
def _removeFormattingFromMathjax(self, txt, ord) -> str: @classmethod
def _removeFormattingFromMathjax(cls, txt, ord) -> str:
"""Marks all clozes within MathJax to prevent formatting them. """Marks all clozes within MathJax to prevent formatting them.
Active Cloze deletions within MathJax should not be wrapped inside Active Cloze deletions within MathJax should not be wrapped inside