From 65da5adf52353686d398671545fa3d5af131ee36 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Thu, 24 Sep 2020 21:44:05 +0100 Subject: [PATCH] typing, docstrings --- CHANGELOG.md | 3 ++- rich/progress.py | 2 +- rich/table.py | 4 ++-- rich/tabulate.py | 4 ++-- rich/traceback.py | 14 ++++++++++++++ 5 files changed, 21 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e411978e..34b0bd1f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added -- Added Console.capture method +- Added Console.begin_capture, Console.end_capture and Console.capture +- Added Table.title_justify and Table.caption_justify https://github.com/willmcgugan/rich/issues/301 ### Changed diff --git a/rich/progress.py b/rich/progress.py index b614b3e4..72ec5e7b 100644 --- a/rich/progress.py +++ b/rich/progress.py @@ -205,7 +205,7 @@ class TextColumn(ProgressColumn): self.highlighter = highlighter super().__init__() - def render(self, task: "Task"): + def render(self, task: "Task") -> Text: _text = self.text_format.format(task=task) if self.markup: text = Text.from_markup(_text, style=self.style, justify=self.justify) diff --git a/rich/table.py b/rich/table.py index 2fa94e6c..78015bb9 100644 --- a/rich/table.py +++ b/rich/table.py @@ -108,8 +108,8 @@ class Table(JupyterMixin): border_style (Union[str, Style], optional): Style of the border. Defaults to None. title_style (Union[str, Style], optional): Style of the title. Defaults to None. caption_style (Union[str, Style], optional): Style of the caption. Defaults to None. - title_justify (str, optional): Justification for title. Defaults to "center". - caption_justify (str, optional): Justification for caption. Defaults to "center". + title_justify (str, optional): Justify method for title. Defaults to "center". + caption_justify (str, optional): Justify method for caption. Defaults to "center". """ columns: List[Column] diff --git a/rich/tabulate.py b/rich/tabulate.py index bb559892..2966948f 100644 --- a/rich/tabulate.py +++ b/rich/tabulate.py @@ -22,8 +22,8 @@ def tabulate_mapping( mapping (Mapping): A mapping object (e.g. a dict); title (str, optional): Optional title to be displayed over the table. caption (str, optional): Optional caption to be displayed below the table. - title_justify (str, optional): Optional "right", "center", "left" string indicating title justification - caption_justify (str, optional): Optional "right", "center", "left" string indicating caption justification + title_justify (str, optional): Justify method for title. Defaults to None. + caption_justify (str, optional): Justify method for caption. Defaults to None. Returns: Table: A table instance which may be rendered by the Console. diff --git a/rich/traceback.py b/rich/traceback.py index 5dab2cec..9cf09d26 100644 --- a/rich/traceback.py +++ b/rich/traceback.py @@ -154,6 +154,20 @@ class Traceback: theme: Optional[str] = None, word_wrap: bool = False, ) -> "Traceback": + """Create a traceback from exception info + + Args: + exc_type (Type[BaseException]): Exception type. + exc_value (BaseException): Exception value. + traceback (TracebackType): Python Traceback object. + width (Optional[int], optional): Number of characters used to traceback. Defaults to 100. + extra_lines (int, optional): Additional lines of code to render. Defaults to 3. + theme (str, optional): Override pygments theme used in traceback. + word_wrap (bool, optional): Enable word wrapping of long lines. Defaults to False. + + Returns: + Traceback: A Traceback instance that may be printed. + """ rich_traceback = cls.extract(exc_type, exc_value, traceback) return Traceback( rich_traceback,