diff options
author | Jonathan Slenders <jonathan@slenders.be> | 2018-05-19 22:11:29 +0200 |
---|---|---|
committer | Jonathan Slenders <jonathan@slenders.be> | 2018-05-19 22:11:29 +0200 |
commit | a317e7d526c3e0b502e3352bcfc29fceb9c68911 (patch) | |
tree | 645fb516b75bc4e3261d1bcb5c8be60982ad66e6 | |
parent | 3d4196df7414c7304d001e28aa0a21d3dc0ebb48 (diff) |
Python 2 fixes for progress bar implementation.
-rw-r--r-- | prompt_toolkit/shortcuts/progress_bar/base.py | 6 | ||||
-rw-r--r-- | prompt_toolkit/utils.py | 7 |
2 files changed, 10 insertions, 3 deletions
diff --git a/prompt_toolkit/shortcuts/progress_bar/base.py b/prompt_toolkit/shortcuts/progress_bar/base.py index b111396d..8e35c30d 100644 --- a/prompt_toolkit/shortcuts/progress_bar/base.py +++ b/prompt_toolkit/shortcuts/progress_bar/base.py @@ -128,7 +128,9 @@ class progress_bar(object): return formatter.get_width(progress_bar=self) progress_controls = [ - Window(content=_ProgressControl(self, f), width=functools.partial(width_for_formatter, f)) + Window( + content=_ProgressControl(self, f), + width=functools.partial(width_for_formatter, f)) for f in self.formatters ] @@ -289,7 +291,7 @@ class ProgressBarCounter(object): """ Timedelta representing the time left. """ - if self.total is None: + if self.total is None or not self.percentage: return None else: return self.time_elapsed * (100 - self.percentage) / self.percentage diff --git a/prompt_toolkit/utils.py b/prompt_toolkit/utils.py index f1cc66fa..062fc7b1 100644 --- a/prompt_toolkit/utils.py +++ b/prompt_toolkit/utils.py @@ -6,6 +6,7 @@ import sys import threading import weakref +from functools import partial from six import PY2 from six.moves import range from wcwidth import wcwidth @@ -121,7 +122,11 @@ def test_callable_args(func, args): else: return True else: - # For older Python versions, fall back to using getargspec. + # For older Python versions, fall back to using getargspec + # and don't check for `partial`. + if isinstance(func, partial): + return True + spec = inspect.getargspec(func) # Drop the 'self' |