Skip to content

Commit

Permalink
change entry.detectDefiFormat to accept default and return str
Browse files Browse the repository at this point in the history
  • Loading branch information
ilius committed Dec 7, 2024
1 parent bb949c5 commit 2c2ec92
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
24 changes: 15 additions & 9 deletions pyglossary/entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,15 +299,21 @@ def defiFormat(self, defiFormat: str) -> None:
"""
self._defiFormat = defiFormat

def detectDefiFormat(self) -> None:
if self._defiFormat != "m":
return
if Entry.xdxfPattern.match(self.defi):
self._defiFormat = "x"
return
if Entry.htmlPattern.match(self.defi):
self._defiFormat = "h"
return
def detectDefiFormat(self, default: str = "") -> str:
if self._defiFormat == "h":
return "h"
if self._defiFormat == "x":
return "x"
if self._defiFormat == "m":
if Entry.xdxfPattern.match(self.defi):
self._defiFormat = "x"
return "x"
if Entry.htmlPattern.match(self.defi):
self._defiFormat = "h"
return "h"
return "m"
log.error(f"invalid defiFormat={self._defiFormat}, using {default!r}")
return default

def byteProgress(self) -> tuple[int, int] | None:
return self._byteProgress
Expand Down
2 changes: 1 addition & 1 deletion pyglossary/glossary_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def defiFormat(self, defiFormat: str) -> None:
# TODO: type: Literal["m", "h", "x", "b"]
...

def detectDefiFormat(self) -> None: ...
def detectDefiFormat(self, default: str = "") -> str: ...

def addAlt(self, alt: str) -> None: ...

Expand Down

0 comments on commit 2c2ec92

Please sign in to comment.