-
Notifications
You must be signed in to change notification settings - Fork 0
tqdm 5 #13
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
base: main
Are you sure you want to change the base?
tqdm 5 #13
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -748,19 +748,12 @@ def __init__(self, iterable=None, desc=None, total=None, leave=True, | |
| if disable is None and hasattr(file, "isatty") and not file.isatty(): | ||
| disable = True | ||
|
|
||
| if total is None and iterable is not None: | ||
| try: | ||
| total = len(iterable) | ||
| except (TypeError, AttributeError): | ||
| total = None | ||
|
|
||
| if disable: | ||
| self.iterable = iterable | ||
| self.disable = disable | ||
| self.pos = self._get_free_pos(self) | ||
| self._instances.remove(self) | ||
| self.n = initial | ||
| self.total = total | ||
| return | ||
|
|
||
| if kwargs: | ||
|
|
@@ -773,6 +766,12 @@ def __init__(self, iterable=None, desc=None, total=None, leave=True, | |
| else TqdmKeyError("Unknown argument(s): " + str(kwargs))) | ||
|
|
||
| # Preprocess the arguments | ||
| if total is None and iterable is not None: | ||
| try: | ||
| total = len(iterable) | ||
| except (TypeError, AttributeError): | ||
| total = None | ||
|
|
||
|
Comment on lines
+769
to
+774
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainLGTM! The total inference logic repositioning improves initialization flow. The refactoring to move total inference after argument validation is a logical improvement. The code correctly handles the case where This change ensures that argument validation occurs before any processing, which is a better practice and can improve performance in error cases. However, since this changes the initialization order and the AI summary mentions that related test coverage was removed, let's verify that this doesn't break existing functionality: 🏁 Script executed: #!/bin/bash
# Description: Search for any code that might depend on total being set early in initialization
# Search for any references to self.total in early return paths or disabled cases
rg -A 5 -B 5 "self\.total.*disable"
# Search for any tests or code that might depend on total being available when disabled
rg -A 10 "disable.*total|total.*disable"
# Search for any boolean evaluation tests that might have been affected
rg -A 5 -B 5 "test.*bool|bool.*test"Length of output: 21613 🏁 Script executed: #!/bin/bash
# Verify boolean special methods and test presence in tqdm_5
# Search for __bool__ method
rg -n "def __bool__" tqdm_5/tqdm/_tqdm.py
# Search for __nonzero__ method (Py2 compatibility)
rg -n "def __nonzero__" tqdm_5/tqdm/_tqdm.py
# Check if boolean evaluation test exists in version 5
grep -R "def test_bool" -n tqdm_5/tqdm/tests/tests_tqdm.pyLength of output: 151 Boolean evaluation support missing in tqdm class The recent refactoring removed the Please restore boolean‐casting behavior: • In def __bool__(self):
return not self.disable and (self.total is None or self.total != 0)
__nonzero__ = __bool__ # for Py2 compatibility• In
This will preserve backward‐compatible truthiness semantics. 🤖 Prompt for AI Agents |
||
| if ((ncols is None) and (file in (sys.stderr, sys.stdout))) or \ | ||
| dynamic_ncols: # pragma: no cover | ||
| if dynamic_ncols: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1560,37 +1560,6 @@ def test_threading(): | |
| # TODO: test interleaved output #445 | ||
|
|
||
|
|
||
| @with_setup(pretest, posttest) | ||
| def test_bool(): | ||
| """Test boolean cast""" | ||
| def internal(our_file, disable): | ||
| with tqdm(total=10, file=our_file, disable=disable) as t: | ||
| assert t | ||
| with tqdm(total=0, file=our_file, disable=disable) as t: | ||
| assert not t | ||
| with trange(10, file=our_file, disable=disable) as t: | ||
| assert t | ||
| with trange(0, file=our_file, disable=disable) as t: | ||
| assert not t | ||
| with tqdm([], file=our_file, disable=disable) as t: | ||
| assert not t | ||
| with tqdm([0], file=our_file, disable=disable) as t: | ||
| assert t | ||
| with tqdm(file=our_file, disable=disable) as t: | ||
| try: | ||
| print(bool(t)) | ||
| except TypeError: | ||
| pass | ||
| else: | ||
| raise TypeError( | ||
| "Expected tqdm() with neither total nor iterable to fail") | ||
|
|
||
| # test with and without disable | ||
| with closing(StringIO()) as our_file: | ||
| internal(our_file, False) | ||
| internal(our_file, True) | ||
|
|
||
|
Comment on lines
-1563
to
-1592
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔴 Error 🐛 BugRemoval of test enforcing TypeError for bool(tqdm()) with no total or iterable. Issue Explanation
Reply if you have any questions or let me know if I missed something. Don't forget to react with a 👍 or 👎 to the comments made by Blar to help us improve. |
||
|
|
||
| @with_setup(pretest, posttest) | ||
| def test_autonotebook(): | ||
| """Test autonotebook fallback""" | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟠 Warning 🐛 Bug
AttributeError can occur if self.total is not set for disabled tqdm instances.
Issue Explanation
__init__method, the assignmentself.total = totalwas removed inside thedisablebranch.disable=True) might not haveself.totalinitialized.__len__method accessesself.totalwithout a fallback ifself.iterableis None, which will raise AttributeError.self.totalin the disable branch is a regression causing potential runtime errors.Reply if you have any questions or let me know if I missed something.
Don't forget to react with a 👍 or 👎 to the comments made by Blar to help us improve.