Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion marimo/_plugins/stateless/status/_progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ def __init__(
self.step: int = 1
self.collection = collection
self._is_async = isinstance(collection, AsyncIterable)
total_was_provided = total is not None

if collection is not None:
if total is None:
Expand All @@ -404,7 +405,7 @@ def __init__(
"A `total` must be provided."
)

if isinstance(collection, range):
elif total_was_provided and isinstance(collection, range):
self.step = cast(range, collection).step

elif total is None:
Expand Down
16 changes: 16 additions & 0 deletions tests/_plugins/stateless/status/test_progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading