Add Styles.reset method revert internal attributes to None

This commit is contained in:
Darren Burns
2022-01-18 14:13:40 +00:00
parent ea40177db9
commit 1410648e36
3 changed files with 16 additions and 1 deletions

View File

@@ -235,6 +235,10 @@ class Styles:
else:
return None
def reset(self) -> None:
for rule_name in INTERNAL_RULE_NAMES:
setattr(self, rule_name, None)
def extract_rules(
self, specificity: Specificity3
) -> list[tuple[str, Specificity4, Any]]:

View File

@@ -114,7 +114,7 @@ class Stylesheet:
_check_rule = self._check_rule
node.reset_styles()
node.styles.reset()
# Get the default node CSS rules
for key, default_specificity, value in node._default_rules:

11
tests/test_styles.py Normal file
View File

@@ -0,0 +1,11 @@
from rich.style import Style
from textual.css.styles import Styles
def test_styles_reset():
styles = Styles()
styles.text_style = "not bold"
assert styles.text_style == Style(bold=False)
styles.reset()
assert styles.text_style is Style.null()