mirror of
https://github.com/nvbn/thefuck.git
synced 2025-02-21 20:38:54 +00:00
Fix cache problem when going from Python 3 to 2
This commit is contained in:
parent
9c9a7343de
commit
cb6f964a30
@ -4,6 +4,7 @@ import pickle
|
|||||||
import pkg_resources
|
import pkg_resources
|
||||||
import re
|
import re
|
||||||
import shelve
|
import shelve
|
||||||
|
import six
|
||||||
from .conf import settings
|
from .conf import settings
|
||||||
from contextlib import closing
|
from contextlib import closing
|
||||||
from decorator import decorator
|
from decorator import decorator
|
||||||
@ -15,6 +16,11 @@ from warnings import warn
|
|||||||
|
|
||||||
DEVNULL = open(os.devnull, 'w')
|
DEVNULL = open(os.devnull, 'w')
|
||||||
|
|
||||||
|
shelve_open_errors = (dbm.error, )
|
||||||
|
if six.PY2:
|
||||||
|
import gdbm
|
||||||
|
shelve_open_errors += (gdbm.error, )
|
||||||
|
|
||||||
|
|
||||||
def memoize(fn):
|
def memoize(fn):
|
||||||
"""Caches previous calls to the function."""
|
"""Caches previous calls to the function."""
|
||||||
@ -217,8 +223,8 @@ def cache(*depends_on):
|
|||||||
value = fn(*args, **kwargs)
|
value = fn(*args, **kwargs)
|
||||||
db[key] = {'etag': etag, 'value': value}
|
db[key] = {'etag': etag, 'value': value}
|
||||||
return value
|
return value
|
||||||
except dbm.error:
|
except shelve_open_errors:
|
||||||
# Caused when going from Python 2 to Python 3
|
# Caused when going from Python 2 to Python 3 and vice-versa
|
||||||
warn("Removing possibly out-dated cache")
|
warn("Removing possibly out-dated cache")
|
||||||
os.remove(cache_path)
|
os.remove(cache_path)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user