mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Rename Key to StringKey to prevent clash with keyboard Keys
This commit is contained in:
@@ -36,7 +36,7 @@ class CellDoesNotExist(Exception):
|
||||
|
||||
|
||||
# TODO: Revisit?
|
||||
class Key(NamedTuple):
|
||||
class StringKey(NamedTuple):
|
||||
value: str | None
|
||||
|
||||
def __hash__(self):
|
||||
@@ -70,7 +70,7 @@ def default_cell_formatter(obj: object) -> RenderableType | None:
|
||||
class Column:
|
||||
"""Table column."""
|
||||
|
||||
key: Key
|
||||
key: StringKey
|
||||
label: Text
|
||||
width: int = 0
|
||||
visible: bool = False
|
||||
@@ -93,7 +93,7 @@ class Column:
|
||||
class Row:
|
||||
"""Table row."""
|
||||
|
||||
key: Key
|
||||
key: StringKey
|
||||
index: int
|
||||
height: int
|
||||
y: int
|
||||
@@ -467,7 +467,7 @@ class DataTable(ScrollView, Generic[CellType], can_focus=True):
|
||||
"""
|
||||
text_label = Text.from_markup(label) if isinstance(label, str) else label
|
||||
|
||||
column_key = Key(key)
|
||||
column_key = StringKey(key)
|
||||
content_width = measure(self.app.console, text_label, 1)
|
||||
if width is None:
|
||||
column = Column(
|
||||
@@ -502,7 +502,7 @@ class DataTable(ScrollView, Generic[CellType], can_focus=True):
|
||||
key: A key which uniquely identifies this row. If None, it will be generated for you. Defaults to None.
|
||||
"""
|
||||
row_index = self.row_count
|
||||
row_key = Key(key)
|
||||
row_key = StringKey(key)
|
||||
|
||||
self.data[row_index] = list(cells)
|
||||
self.rows[row_index] = Row(row_key, row_index, height, self._line_no)
|
||||
|
||||
@@ -2,7 +2,7 @@ from textual.app import App
|
||||
from textual.coordinate import Coordinate
|
||||
from textual.message import Message
|
||||
from textual.widgets import DataTable
|
||||
from textual.widgets._data_table import Key
|
||||
from textual.widgets._data_table import StringKey
|
||||
|
||||
|
||||
class DataTableApp(App):
|
||||
@@ -152,13 +152,13 @@ async def test_clear():
|
||||
|
||||
def test_key_equals_equivalent_string():
|
||||
text = "Hello"
|
||||
key = Key(text)
|
||||
key = StringKey(text)
|
||||
assert key == text
|
||||
assert hash(key) == hash(text)
|
||||
|
||||
|
||||
def test_key_doesnt_match_non_equal_string():
|
||||
key = Key("123")
|
||||
key = StringKey("123")
|
||||
text = "laksjdlaskjd"
|
||||
assert key != text
|
||||
assert hash(key) != hash(text)
|
||||
@@ -169,9 +169,9 @@ def test_key_string_lookup():
|
||||
# in tests how we intend for the keys to work for cache lookups.
|
||||
dictionary = {
|
||||
"foo": "bar",
|
||||
Key("hello"): "world",
|
||||
StringKey("hello"): "world",
|
||||
}
|
||||
assert dictionary["foo"] == "bar"
|
||||
assert dictionary[Key("foo")] == "bar"
|
||||
assert dictionary[StringKey("foo")] == "bar"
|
||||
assert dictionary["hello"] == "world"
|
||||
assert dictionary[Key("hello")] == "world"
|
||||
assert dictionary[StringKey("hello")] == "world"
|
||||
|
||||
Reference in New Issue
Block a user