diff --git a/parso/cache.py b/parso/cache.py index 0165398..5514a59 100644 --- a/parso/cache.py +++ b/parso/cache.py @@ -82,9 +82,8 @@ def load_module(hashed_grammar, file_io, cache_path=None): """ Returns a module or None, if it fails. """ - try: - p_time = file_io.get_last_modified() - except FileNotFoundError: + p_time = file_io.get_last_modified() + if p_time is None: return None try: diff --git a/parso/file_io.py b/parso/file_io.py index 64154f9..94fe08e 100644 --- a/parso/file_io.py +++ b/parso/file_io.py @@ -14,10 +14,13 @@ class FileIO(object): def get_last_modified(self): """ - Returns float - timestamp - Might raise FileNotFoundError + Returns float - timestamp or None, if path doesn't exist. """ - return os.path.getmtime(self.path) + try: + return os.path.getmtime(self.path) + except OSError: + # Might raise FileNotFoundError, OSError for Python 2 + return None def __repr__(self): return '%s(%s)' % (self.__class__.__name__, self.path)