From a26822b257e187969f9f2dcef0e17af88650995d Mon Sep 17 00:00:00 2001 From: Olivier Philippon Date: Tue, 3 May 2022 17:10:00 +0100 Subject: [PATCH] [css] Add some docstrings following "did you mean" PR feedback --- src/textual/css/_styles_builder.py | 12 ++++++++++++ src/textual/suggestions.py | 20 +++++++++++++++++--- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/textual/css/_styles_builder.py b/src/textual/css/_styles_builder.py index 4ccf04ef6..2c72e13d3 100644 --- a/src/textual/css/_styles_builder.py +++ b/src/textual/css/_styles_builder.py @@ -119,6 +119,11 @@ class StylesBuilder: """ Returns the list of CSS properties we can manage - i.e. the ones for which we have a `process_[property name]` method + + Returns: + Sequence[str]: All the "Python-ised" CSS property names this class can handle. + + Example: ("width", "background", "offset_x", ...) """ return [attr[8:] for attr in dir(self) if attr.startswith("process_")] @@ -751,6 +756,13 @@ class StylesBuilder: """ Returns a valid CSS property "Python" name, or None if no close matches could be found. + Args: + rule_name (str): An invalid "Python-ised" CSS property (i.e. "offst_x" rather than "offst-x") + + Returns: + str | None: The closest valid "Python-ised" CSS property. + Returns `None` if no close matches could be found. + Example: returns "background" for rule_name "bkgrund", "offset_x" for "ofset_x" """ return get_suggestion(rule_name, self._get_processable_rule_names()) diff --git a/src/textual/suggestions.py b/src/textual/suggestions.py index ffe9af2df..e3fb20db2 100644 --- a/src/textual/suggestions.py +++ b/src/textual/suggestions.py @@ -6,7 +6,14 @@ from typing import Sequence def get_suggestion(word: str, possible_words: Sequence[str]) -> str | None: """ - Returns a close match of 'word' amongst 'possible_words', or None if no close matches could be found. + Returns a close match of `word` amongst `possible_words`. + + Args: + word (str): The word we want to find a close match for + possible_words (Sequence[str]): The words amongst which we want to find a close match + + Returns: + str | None: The closest match amongst the `possible_words`. Returns `None` if no close matches could be found. Example: returns "red" for word "redu" and possible words ("yellow", "red") """ @@ -16,8 +23,15 @@ def get_suggestion(word: str, possible_words: Sequence[str]) -> str | None: def get_suggestions(word: str, possible_words: Sequence[str], count: int) -> list[str]: """ - Returns a list of up to 'count' matches of 'word' amongst 'possible_words' - - or an empty list if no close matches could be found. + Returns a list of up to `count` matches of `word` amongst `possible_words`. + + Args: + word (str): The word we want to find a close match for + possible_words (Sequence[str]): The words amongst which we want to find close matches + + Returns: + list[str]: The closest matches amongst the `possible_words`, from the closest to the least close. + Returns an empty list if no close matches could be found. Example: returns ["yellow", "ellow"] for word "yllow" and possible words ("yellow", "red", "ellow") """