Skip to content

Commit

Permalink
Correctly delegate to super formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
kg583 committed Nov 17, 2024
1 parent 8e331bb commit 93ca4da
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions tivars/types/tokenized.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ class TokenizedEntry(SizedEntry):
"""

def __format__(self, format_spec: str) -> str:
if "." not in format_spec:
format_spec += ".en"
try:
if "." not in format_spec:
format_spec += ".en"

lines, conv, sep, spec, lang = re.match(r"(.*?)(\w?)(\W*)?(\w?)\.(\w+)", format_spec).groups()
line_number = f"{{index:{lines}{conv or 'd'}}}{sep}" if conv or lines else sep
lines, conv, sep, spec, lang = re.match(r"(.*?)(\w?)(\W*)?(\w?)\.(\w+)", format_spec).groups()
line_number = f"{{index:{lines}{conv or 'd'}}}{sep}" if conv or lines else sep

try:
match spec:
case "" | "t":
string = self.decode(self.data, lang=lang)
Expand All @@ -61,10 +61,8 @@ def __format__(self, format_spec: str) -> str:

return "\n".join(line_number.format(index=index) + line for index, line in enumerate(string.split("\n")))

except KeyError:
pass

return super().__format__(format_spec)
except (AttributeError, KeyError, ValueError, TypeError):
return super().__format__(format_spec)

@staticmethod
def decode(data: bytes, *, lang: str = "en", mode: str = "display") -> str | bytes:
Expand Down

0 comments on commit 93ca4da

Please sign in to comment.