# Buggy code
def format_dict(self):
    """Public API for read-only member access."""
    if self.dynamic_ncols:
        self.ncols, self.nrows = self.dynamic_ncols(self.fp)
    ncols, nrows = self.ncols, self.nrows
    return {
        "n": self.n,
        "total": self.total,
        "elapsed": self._time() - self.start_t if hasattr(self, "start_t") else 0,
        "ncols": ncols,
        "nrows": nrows,
        "prefix": self.desc,
        "ascii": self.ascii,
        "unit": self.unit,
        "unit_scale": self.unit_scale,
        "rate": self._ema_dn() / self._ema_dt() if self._ema_dt() else None,
        "bar_format": self.bar_format,
        "postfix": self.postfix,
        "unit_divisor": self.unit_divisor,
        "initial": self.initial,
        "colour": self.colour,
    }


# Traceback (AttributeError)
import tqdm, sys
print(tqdm.__version__, sys.version, sys.platform)
('4.26.0', '2.7.14 (default, Mar 22 2018, 15:04:47) \n[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)]', 'darwin')
a = tqdm.tqdm([], disable=True)
print a
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/kratsg/.virtualenvs/pyhf/lib/python2.7/site-packages/tqdm/_tqdm.py", line 894, in __repr__
elapsed if elapsed is not None else self._time() - self.start_t,
AttributeError: 'tqdm' object has no attribute '_time'
str(a)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/kratsg/.virtualenvs/pyhf/lib/python2.7/site-packages/tqdm/_tqdm.py", line 894, in __repr__
elapsed if elapsed is not None else self._time() - self.start_t,
AttributeError: 'tqdm' object has no attribute '_time'
dir(a)
['__class__', '__del__', '__delattr__', '__dict__', '__doc__', '__enter__', '__eq__', '__exit__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_comparable', '_decr_instances', '_get_free_pos', '_instances', '_lock', 'clear', 'close', 'disable', 'external_write_mode', 'format_interval', 'format_meter', 'format_sizeof', 'get_lock', 'iterable', 'monitor', 'monitor_interval', 'moveto', 'n', 'pandas', 'pos', 'refresh', 'set_description', 'set_description_str', 'set_lock', 'set_postfix', 'set_postfix_str', 'status_printer', 'total', 'unpause', 'update', 'write']

# Fixed code
def format_dict(self):
    """Public API for read-only member access."""
    if self.disable and not hasattr(self, "unit"):
        return defaultdict(
            lambda: None, {"n": self.n, "total": self.total, "elapsed": 0, "unit": "it"}
        )
    if self.dynamic_ncols:
        self.ncols, self.nrows = self.dynamic_ncols(self.fp)
    return {
        "n": self.n,
        "total": self.total,
        "elapsed": self._time() - self.start_t if hasattr(self, "start_t") else 0,
        "ncols": self.ncols,
        "nrows": self.nrows,
        "prefix": self.desc,
        "ascii": self.ascii,
        "unit": self.unit,
        "unit_scale": self.unit_scale,
        "rate": self._ema_dn() / self._ema_dt() if self._ema_dt() else None,
        "bar_format": self.bar_format,
        "postfix": self.postfix,
        "unit_divisor": self.unit_divisor,
        "initial": self.initial,
        "colour": self.colour,
    }