From b18a31eb261e332de6f263646bb5aaca7ac56e6d Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Sun, 28 Jun 2020 20:39:18 +0100 Subject: [PATCH] notebook: cleaner `ipywidgets` ImportError - more succinct traceback - fixes #872 --- tqdm/notebook.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/tqdm/notebook.py b/tqdm/notebook.py index 57051037..79a5ccd0 100644 --- a/tqdm/notebook.py +++ b/tqdm/notebook.py @@ -56,6 +56,7 @@ if True: # pragma: no cover IPY = 2 except ImportError: IPY = 0 + IProgress = None try: from IPython.display import display # , clear_output @@ -91,19 +92,17 @@ class tqdm_notebook(std_tqdm): # fp = file # Prepare IPython progress bar - try: - if total: - pbar = IProgress(min=0, max=total) - else: # No total? Show info style bar with no progress tqdm status - pbar = IProgress(min=0, max=1) - pbar.value = 1 - pbar.bar_style = 'info' - except NameError: - # #187 #451 #558 + if IProgress is None: # #187 #451 #558 #872 raise ImportError( - "FloatProgress not found. Please update jupyter and ipywidgets." + "IProgress not found. Please update jupyter and ipywidgets." " See https://ipywidgets.readthedocs.io/en/stable" "/user_install.html") + if total: + pbar = IProgress(min=0, max=total) + else: # No total? Show info style bar with no progress tqdm status + pbar = IProgress(min=0, max=1) + pbar.value = 1 + pbar.bar_style = 'info' if desc: pbar.description = desc