Skip to content

Commit

Permalink
Fix typing around Markdown tables
Browse files Browse the repository at this point in the history
  • Loading branch information
darrenburns committed May 31, 2023
1 parent 4db7de1 commit 4345f51
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions rich/markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,20 +245,24 @@ def __rich_console__(
self, console: Console, options: ConsoleOptions
) -> RenderResult:
table = Table()

assert self.header is not None
assert self.header.row is not None
for column in self.header.row.cells:
table.add_column(column.content)

assert self.body is not None
for row in self.body.rows:
row = [element.content for element in row.cells]
table.add_row(*row)
row_content = [element.content for element in row.cells]
table.add_row(*row_content)

yield table


class TableHeaderElement(MarkdownElement):
"""MarkdownElement corresponding to `thead_open` and `thead_close`."""

def __init__(self):
def __init__(self) -> None:
self.row: TableRowElement | None = None

def on_child_close(
Expand All @@ -272,7 +276,7 @@ def on_child_close(
class TableBodyElement(MarkdownElement):
"""MarkdownElement corresponding to `tbody_open` and `tbody_close`."""

def __init__(self):
def __init__(self) -> None:
self.rows: list[TableRowElement] = []

def on_child_close(
Expand All @@ -286,7 +290,7 @@ def on_child_close(
class TableRowElement(MarkdownElement):
"""MarkdownElement corresponding to `tr_open` and `tr_close`."""

def __init__(self):
def __init__(self) -> None:
self.cells: List[TableDataElement] = []

def on_child_close(
Expand All @@ -301,8 +305,8 @@ class TableDataElement(MarkdownElement):
"""MarkdownElement corresponding to `td_open` and `td_close`
and `th_open` and `th_close`."""

def __init__(self):
self.content = ""
def __init__(self) -> None:
self.content: TextType = ""

def on_text(self, context: "MarkdownContext", text: TextType) -> None:
self.content = text
Expand Down

0 comments on commit 4345f51

Please sign in to comment.