Skip to content

Commit

Permalink
Propagate entry formats for containers
Browse files Browse the repository at this point in the history
  • Loading branch information
kg583 committed Nov 16, 2024
1 parent e14a6d6 commit d6abb90
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
6 changes: 2 additions & 4 deletions tivars/types/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,10 @@ def __init__(self, init=None, *,

def __format__(self, format_spec: str) -> str:
match format_spec:
case "":
return "[" + ", ".join(format(entry, format_spec) for entry in self.list()) + "]"
case "t":
return "{" + ",".join(format(entry, 't') for entry in self.list()) + "}"
return "{" + ",".join(format(entry, "t") for entry in self.list()) + "}"
case _:
return super().__format__(format_spec)
return "[" + ", ".join(format(entry, format_spec) for entry in self.list()) + "]"

def __iter__(self) -> Iterator[_E]:
return iter(self.list())
Expand Down
4 changes: 1 addition & 3 deletions tivars/types/matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,10 @@ def __init__(self, init=None, *,

def __format__(self, format_spec: str) -> str:
match format_spec:
case "":
inner_sep, outer_sep = ", ", ", "
case "t":
inner_sep, outer_sep = ",", ""
case _:
return super().__format__(format_spec)
inner_sep, outer_sep = ", ", ", "

return "[" + outer_sep.join(f"[{inner_sep.join(format(entry, format_spec) for entry in row)}]"
for row in self.matrix()) + "]"
Expand Down

0 comments on commit d6abb90

Please sign in to comment.