Skip to content

Instantly share code, notes, and snippets.

@shuckc
Created August 6, 2023 09:12
Show Gist options
  • Save shuckc/4b5a2650b9853c7564541c5a0ed942a9 to your computer and use it in GitHub Desktop.
Save shuckc/4b5a2650b9853c7564541c5a0ed942a9 to your computer and use it in GitHub Desktop.
from textual.app import App, ComposeResult
from textual.widgets import DataTable
from typing import Dict
ROWS = [
(4, "Joseph Schooling", "Singapore", 50.39),
(1, "Aleksandr Sadovnikov", "Russia", 51.84),
(10, "Darren Burns", "Scotland", 51.84),
]
class TableApp(App):
def __init__(self):
super().__init__()
self.rowkeys: Dict[int,RowKey] = {}
def compose(self) -> ComposeResult:
yield DataTable()
def on_mount(self) -> None:
table = self.query_one(DataTable)
table.add_columns("lane", "swimmer", "country", "time")
for i,r in enumerate(ROWS):
rk = table.add_row(*r)
self.rowkeys[i] = rk
app = TableApp()
if __name__ == "__main__":
app.run()
$ mypy --check-untyped-defs dt_test.py
dt_test.py:15: error: Name "RowKey" is not defined [name-defined]
Found 1 error in 1 file (checked 1 source file)
@shuckc
Copy link
Author

shuckc commented Aug 6, 2023

OK with from textual.widgets._data_table import RowKey added, I get clean output:

$ mypy --check-untyped-defs dt_test.py 
Success: no issues found in 1 source file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment