From b6441d04173ba8f57843cd3051d053c2d77e944f Mon Sep 17 00:00:00 2001 From: Darren Burns Date: Tue, 14 Feb 2023 13:57:08 +0000 Subject: [PATCH] Formatting docstrings to match style guide --- src/textual/_two_way_dict.py | 4 +++- src/textual/widgets/_data_table.py | 20 ++++++++++---------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/textual/_two_way_dict.py b/src/textual/_two_way_dict.py index b75543977..d733edcdc 100644 --- a/src/textual/_two_way_dict.py +++ b/src/textual/_two_way_dict.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import TypeVar, Generic +from typing import Generic, TypeVar Key = TypeVar("Key") Value = TypeVar("Value") @@ -8,6 +8,8 @@ Value = TypeVar("Value") class TwoWayDict(Generic[Key, Value]): """ + A two-way mapping offering O(1) access in both directions. + Wraps two dictionaries and uses them to provide efficient access to both values (given keys) and keys (given values). """ diff --git a/src/textual/widgets/_data_table.py b/src/textual/widgets/_data_table.py index b195b1ac4..c5381de5b 100644 --- a/src/textual/widgets/_data_table.py +++ b/src/textual/widgets/_data_table.py @@ -41,12 +41,16 @@ CellType = TypeVar("CellType") class CellDoesNotExist(Exception): - """Raised when the user supplies coordinates or cell keys which + """The cell key/index was invalid. + + Raised when the user supplies coordinates or cell keys which do not exist in the DataTable.""" class DuplicateKey(Exception): - """Raised when the RowKey or ColumnKey provided already refers to + """The key supplied already exists. + + Raised when the RowKey or ColumnKey provided already refers to an existing row or column in the DataTable. Keys must be unique.""" @@ -120,8 +124,7 @@ class CellKey(NamedTuple): def default_cell_formatter(obj: object) -> RenderableType: - """Given an object stored in a DataTable cell, return a Rich - renderable type which displays that object. + """Convert a cell into a Rich renderable for display. Args: obj: Data for a cell. @@ -561,8 +564,7 @@ class DataTable(ScrollView, Generic[CellType], can_focus=True): *, update_width: bool = False, ) -> None: - """Update the content inside the cell with the specified row key - and column key. + """Update the cell identified by the specified row key and column key. Args: row_key: The key identifying the row. @@ -736,8 +738,7 @@ class DataTable(ScrollView, Generic[CellType], can_focus=True): ) def coordinate_to_cell_key(self, coordinate: Coordinate) -> CellKey: - """Return the key for the cell currently occupying this coordinate in the - DataTable + """Return the key for the cell currently occupying this coordinate. Args: coordinate: The coordinate to exam the current cell key of. @@ -1140,8 +1141,7 @@ class DataTable(ScrollView, Generic[CellType], can_focus=True): return 0 <= column_index < len(self.columns) def is_valid_coordinate(self, coordinate: Coordinate) -> bool: - """Return a boolean indicating whether the given coordinate is within table - bounds. + """Return a boolean indicating whether the given coordinate is valid. Args: coordinate: The coordinate to validate.