diff --git a/src/textual/color.py b/src/textual/color.py index 97c1adeca..fd7fd0bd8 100644 --- a/src/textual/color.py +++ b/src/textual/color.py @@ -85,7 +85,7 @@ class ColorParseError(Exception): message (str): the error message suggested_color (str | None): a close color we can suggest. Defaults to None. """ - super().__init__(*[message]) + super().__init__(message) self.suggested_color = suggested_color diff --git a/src/textual/css/_help_renderables.py b/src/textual/css/_help_renderables.py index 3a9d2e5ab..184256687 100644 --- a/src/textual/css/_help_renderables.py +++ b/src/textual/css/_help_renderables.py @@ -70,13 +70,13 @@ class HelpText: Attributes: summary (str): A succinct summary of the issue. - bullets (Iterable[Bullet]): Bullet points which provide additional - context around the issue. These are rendered below the summary. + bullets (Iterable[Bullet] | None): Bullet points which provide additional + context around the issue. These are rendered below the summary. Defaults to None. """ - def __init__(self, summary: str, *, bullets: Iterable[Bullet]) -> None: + def __init__(self, summary: str, *, bullets: Iterable[Bullet] = None) -> None: self.summary = summary - self.bullets = bullets + self.bullets = bullets or [] def __rich_console__( self, console: Console, options: ConsoleOptions diff --git a/src/textual/css/_help_text.py b/src/textual/css/_help_text.py index c64ab3345..b3ed0f3ec 100644 --- a/src/textual/css/_help_text.py +++ b/src/textual/css/_help_text.py @@ -145,13 +145,13 @@ def property_invalid_value_help_text( HelpText: Renderable for displaying the help text for this property """ property_name = _contextualize_property_name(property_name, context) - bullets = [] + summary = f"Invalid CSS property [i]{property_name}[/]" if suggested_property_name: suggested_property_name = _contextualize_property_name( suggested_property_name, context ) - bullets.append(Bullet(f'Did you mean "{suggested_property_name}"?')) - return HelpText(f"Invalid CSS property [i]{property_name}[/]", bullets=bullets) + summary += f'. Did you mean "{suggested_property_name}"?' + return HelpText(summary) def spacing_wrong_number_of_values_help_text( @@ -319,17 +319,15 @@ def color_property_help_text( HelpText: Renderable for displaying the help text for this property """ property_name = _contextualize_property_name(property_name, context) + summary = f"Invalid value for the [i]{property_name}[/] property" suggested_color = ( error.suggested_color if error and isinstance(error, ColorParseError) else None ) + if suggested_color: + summary += f'. Did you mean "{suggested_color}"?' return HelpText( - summary=f"Invalid value for the [i]{property_name}[/] property", + summary=summary, bullets=[ - *( - [Bullet(f'Did you mean "{suggested_color}"?')] - if suggested_color - else [] - ), Bullet( f"The [i]{property_name}[/] property can only be set to a valid color" ), diff --git a/src/textual/css/_style_properties.py b/src/textual/css/_style_properties.py index f8fc13e42..b7a161c71 100644 --- a/src/textual/css/_style_properties.py +++ b/src/textual/css/_style_properties.py @@ -788,7 +788,7 @@ class ColorProperty: help_text=color_property_help_text( self.name, context="inline", error=error ), - ) from error + ) if obj.set_rule(self.name, parsed_color): obj.refresh() else: diff --git a/tests/css/test_stylesheet.py b/tests/css/test_stylesheet.py index 8c5c93e65..9ef433a29 100644 --- a/tests/css/test_stylesheet.py +++ b/tests/css/test_stylesheet.py @@ -90,17 +90,10 @@ def test_did_you_mean_for_css_property_names( _, help_text = err.value.errors.rules[0].errors[0] # type: Any, HelpText displayed_css_property_name = css_property_name.replace("_", "-") - assert ( - help_text.summary == f"Invalid CSS property [i]{displayed_css_property_name}[/]" - ) - - expected_bullets_length = 1 if expected_property_name_suggestion else 0 - assert len(help_text.bullets) == expected_bullets_length - if expected_property_name_suggestion is not None: - expected_suggestion_message = ( - f'Did you mean "{expected_property_name_suggestion}"?' - ) - assert help_text.bullets[0].markup == expected_suggestion_message + expected_summary = f"Invalid CSS property [i]{displayed_css_property_name}[/]" + if expected_property_name_suggestion: + expected_summary += f'. Did you mean "{expected_property_name_suggestion}"?' + assert help_text.summary == expected_summary @pytest.mark.parametrize( @@ -134,14 +127,11 @@ def test_did_you_mean_for_color_names( _, help_text = err.value.errors.rules[0].errors[0] # type: Any, HelpText displayed_css_property_name = css_property_name.replace("_", "-") - assert ( - help_text.summary - == f"Invalid value for the [i]{displayed_css_property_name}[/] property" + expected_error_summary = ( + f"Invalid value for the [i]{displayed_css_property_name}[/] property" ) - first_bullet = help_text.bullets[0] if expected_color_suggestion is not None: - expected_suggestion_message = f'Did you mean "{expected_color_suggestion}"?' - assert first_bullet.markup == expected_suggestion_message - else: - assert "Did you mean" not in first_bullet.markup + expected_error_summary += f'. Did you mean "{expected_color_suggestion}"?' + + assert help_text.summary == expected_error_summary