mirror of
https://github.com/davidhalter/parso.git
synced 2025-12-06 21:04:29 +08:00
Make it clear that get_last_modified should not raise an exception, but return None, if it cannot look up a file
This commit is contained in:
@@ -82,9 +82,8 @@ def load_module(hashed_grammar, file_io, cache_path=None):
|
|||||||
"""
|
"""
|
||||||
Returns a module or None, if it fails.
|
Returns a module or None, if it fails.
|
||||||
"""
|
"""
|
||||||
try:
|
p_time = file_io.get_last_modified()
|
||||||
p_time = file_io.get_last_modified()
|
if p_time is None:
|
||||||
except FileNotFoundError:
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -14,10 +14,13 @@ class FileIO(object):
|
|||||||
|
|
||||||
def get_last_modified(self):
|
def get_last_modified(self):
|
||||||
"""
|
"""
|
||||||
Returns float - timestamp
|
Returns float - timestamp or None, if path doesn't exist.
|
||||||
Might raise FileNotFoundError
|
|
||||||
"""
|
"""
|
||||||
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):
|
def __repr__(self):
|
||||||
return '%s(%s)' % (self.__class__.__name__, self.path)
|
return '%s(%s)' % (self.__class__.__name__, self.path)
|
||||||
|
|||||||
Reference in New Issue
Block a user