Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reflect the length hint in the total of the progress bar #1426

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions tqdm/std.py
Expand Up @@ -12,6 +12,7 @@
from contextlib import contextmanager
from datetime import datetime, timedelta, timezone
from numbers import Number
from operator import length_hint
from time import time
from warnings import warn
from weakref import WeakSet
Expand Down Expand Up @@ -977,7 +978,10 @@ def __init__(self, iterable=None, desc=None, total=None, leave=True, file=None,
try:
total = len(iterable)
except (TypeError, AttributeError):
total = None
try:
total = length_hint(iterable)
except (TypeError, AttributeError):
total = None
if total == float("inf"):
# Infinite iterations, behave same as unknown
total = None
Expand Down Expand Up @@ -1114,7 +1118,7 @@ def __len__(self):
self.total if self.iterable is None
else self.iterable.shape[0] if hasattr(self.iterable, "shape")
else len(self.iterable) if hasattr(self.iterable, "__len__")
else self.iterable.__length_hint__() if hasattr(self.iterable, "__length_hint__")
else length_hint(self.iterable) if hasattr(self.iterable, "__length_hint__")
else getattr(self, "total", None))

def __reversed__(self):
Expand Down