diff --git a/marimo/_plugins/stateless/status/_progress.py b/marimo/_plugins/stateless/status/_progress.py index 82e6ed60ea8..6311acb5a1b 100644 --- a/marimo/_plugins/stateless/status/_progress.py +++ b/marimo/_plugins/stateless/status/_progress.py @@ -404,7 +404,7 @@ def __init__( "A `total` must be provided." ) - if isinstance(collection, range): + elif isinstance(collection, range): self.step = cast(range, collection).step elif total is None: diff --git a/tests/_plugins/stateless/status/test_progress.py b/tests/_plugins/stateless/status/test_progress.py index 2c4978e5d04..81240621dff 100644 --- a/tests/_plugins/stateless/status/test_progress.py +++ b/tests/_plugins/stateless/status/test_progress.py @@ -167,6 +167,22 @@ def test_progress_without_context(): pass +def test_progress_with_stepped_range_without_total() -> None: + assert runtime_context_installed() is False + + progress = progress_bar(range(0, 10, 2)) + assert list(progress) == [0, 2, 4, 6, 8] + assert (progress.progress.current, progress.progress.total) == (5, 5) + + +def test_progress_with_stepped_range_and_total() -> None: + assert runtime_context_installed() is False + + progress = progress_bar(range(0, 10, 2), total=10) + assert list(progress) == [0, 2, 4, 6, 8] + assert (progress.progress.current, progress.progress.total) == (10, 10) + + async def sleep(seconds): import asyncio