From cb6f964a307cd25323eb69346aa7cea9d753e8a0 Mon Sep 17 00:00:00 2001 From: Pablo Santiago Blum de Aguiar Date: Thu, 21 Jan 2016 23:54:31 -0200 Subject: [PATCH] Fix cache problem when going from Python 3 to 2 --- thefuck/utils.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/thefuck/utils.py b/thefuck/utils.py index 1770e05d..101bcd25 100644 --- a/thefuck/utils.py +++ b/thefuck/utils.py @@ -4,6 +4,7 @@ import pickle import pkg_resources import re import shelve +import six from .conf import settings from contextlib import closing from decorator import decorator @@ -15,6 +16,11 @@ from warnings import warn DEVNULL = open(os.devnull, 'w') +shelve_open_errors = (dbm.error, ) +if six.PY2: + import gdbm + shelve_open_errors += (gdbm.error, ) + def memoize(fn): """Caches previous calls to the function.""" @@ -217,8 +223,8 @@ def cache(*depends_on): value = fn(*args, **kwargs) db[key] = {'etag': etag, 'value': value} return value - except dbm.error: - # Caused when going from Python 2 to Python 3 + except shelve_open_errors: + # Caused when going from Python 2 to Python 3 and vice-versa warn("Removing possibly out-dated cache") os.remove(cache_path)