Tweak progress bar docs. (#3286)

* Tweak progress bar docs.

There is no good reason as to why the progress bar can't be set back to its indeterminate state (and you could actually do it with code) so this removes the docstring that says that a progress bar can't go back to its indeterminate state.

Related issue: #3268
Related Discord message: https://discord.com/channels/1026214085173461072/1033754296224841768/1149742624002023594

* Use a special sentinal in ProgressBar.update

To comply with https://github.com/Textualize/textual/pull/3286#pullrequestreview-1628601324 we create a new type around a sentinel object and check whether we're using the sentinel before modifying the progress bar reactives.

Things that didn't quite work well:
- directly checking 'if parameter is not _sentinel:' won't satisfy type checkers because that condition doesn't restrict the type of 'parameter' to _not_ be 'UnsetParameter'.
- checking 'isinstance(parameter, float)' isn't enough because the user may call the method with an integer like '3' and then the isinstance check would fail.

- checking 'isinstance(parameter, (int, float))' works but looks a bit odd, plus it is not very general.

* Rework ProgressBar.update with a sentinel value.
This commit is contained in:
Rodrigo Girão Serrão
2023-09-20 13:51:01 +01:00
committed by GitHub
parent dfba992722
commit 79e9f3bc16
5 changed files with 33 additions and 16 deletions

View File

@@ -79,7 +79,7 @@ def test_update_total():
assert pb.total == 1000
pb.update(total=None)
assert pb.total == 1000
assert pb.total is None
pb.update(total=100)
assert pb.total == 100
@@ -119,6 +119,15 @@ def test_update():
assert pb.progress == 50
def test_go_back_to_indeterminate():
pb = ProgressBar()
pb.total = 100
assert pb.percentage == 0
pb.total = None
assert pb.percentage is None
@pytest.mark.parametrize(
["show_bar", "show_percentage", "show_eta"],
[