From 687f5e4ccf473980a373d7e17208c53dcd9ec60d Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Fri, 3 Mar 2023 20:20:37 +0000 Subject: [PATCH] tech-debt: drop more legacy code --- tqdm/contrib/concurrent.py | 20 ++------------------ tqdm/std.py | 14 +++----------- tqdm/tk.py | 9 ++------- tqdm/utils.py | 13 ++++--------- 4 files changed, 11 insertions(+), 45 deletions(-) diff --git a/tqdm/contrib/concurrent.py b/tqdm/contrib/concurrent.py index 8ec6f59a1..cd81d622a 100644 --- a/tqdm/contrib/concurrent.py +++ b/tqdm/contrib/concurrent.py @@ -2,28 +2,12 @@ Thin wrappers around `concurrent.futures`. """ from contextlib import contextmanager +from operator import length_hint +from os import cpu_count from ..auto import tqdm as tqdm_auto from ..std import TqdmWarning -try: - from operator import length_hint -except ImportError: - def length_hint(it, default=0): - """Returns `len(it)`, falling back to `default`""" - try: - return len(it) - except TypeError: - return default -try: - from os import cpu_count -except ImportError: - try: - from multiprocessing import cpu_count - except ImportError: - def cpu_count(): - return 4 - __author__ = {"github.com/": ["casperdcl"]} __all__ = ['thread_map', 'process_map'] diff --git a/tqdm/std.py b/tqdm/std.py index a038d1d45..1163137e9 100644 --- a/tqdm/std.py +++ b/tqdm/std.py @@ -509,21 +509,16 @@ def format_meter(n, total, elapsed, ncols=None, prefix='', ascii=False, unit='it if bar_format: format_dict.update(percentage=percentage) - # auto-remove colon for empty `desc` + # auto-remove colon for empty `{desc}` if not prefix: bar_format = bar_format.replace("{desc}: ", '') else: bar_format = "{l_bar}{bar}{r_bar}" full_bar = FormatReplace() - try: - nobar = bar_format.format(bar=full_bar, **format_dict) - except UnicodeEncodeError: - bar_format = str(bar_format) - nobar = bar_format.format(bar=full_bar, **format_dict) + nobar = bar_format.format(bar=full_bar, **format_dict) if not full_bar.format_called: - # no {bar}, we can just format and return - return nobar + return nobar # no `{bar}`; nothing else to do # Formatting progress bar space available for bar's display full_bar = Bar(frac, @@ -1111,9 +1106,6 @@ def __bool__(self): raise TypeError('bool() undefined when iterable == total == None') return bool(self.iterable) - def __nonzero__(self): - return self.__bool__() - def __len__(self): return ( self.total if self.iterable is None diff --git a/tqdm/tk.py b/tqdm/tk.py index 2cf8a47b8..7852d80ea 100644 --- a/tqdm/tk.py +++ b/tqdm/tk.py @@ -8,15 +8,10 @@ """ import re import sys +import tkinter +import tkinter.ttk as ttk from warnings import warn -try: - import tkinter - import tkinter.ttk as ttk -except ImportError: - import Tkinter as tkinter - import ttk as ttk - from .std import TqdmExperimentalWarning, TqdmWarning from .std import tqdm as std_tqdm diff --git a/tqdm/utils.py b/tqdm/utils.py index ea3634253..c5d3a6e32 100644 --- a/tqdm/utils.py +++ b/tqdm/utils.py @@ -5,11 +5,12 @@ import re import sys from functools import wraps +# TODO consider using wcswidth third-party package for 0-width characters +from unicodedata import east_asian_width from warnings import warn from weakref import proxy _range, _unich, _unicode, _basestring = range, chr, str, str - CUR_OS = sys.platform IS_WIN = any(CUR_OS.startswith(i) for i in ['win32', 'cygwin']) IS_NIX = any(CUR_OS.startswith(i) for i in ['aix', 'linux', 'darwin']) @@ -301,14 +302,8 @@ def _term_move_up(): # pragma: no cover return '' if (os.name == 'nt') and (colorama is None) else '\x1b[A' -try: - # TODO consider using wcswidth third-party package for 0-width characters - from unicodedata import east_asian_width -except ImportError: - _text_width = len -else: - def _text_width(s): - return sum(2 if east_asian_width(ch) in 'FW' else 1 for ch in str(s)) +def _text_width(s): + return sum(2 if east_asian_width(ch) in 'FW' else 1 for ch in str(s)) def disp_len(data):