Do not test file exists when opening it
The file_open tools may be used to create a file so it may not yet exist. Also io.open will raise the proper exception if the file can not be open. Closes #13230 (grafted from ad09f3e55f6f7bd6767ea44d03566322fce6b487) --HG-- branch : 7.0
This commit is contained in:
1 parent
270851ad9f
commit
9363eafb87
1 file changed
+2
-2
@@ -46,7 +46,7 @@ def import_module(name):
|
||||
|
||||
def file_open(name, mode="r", subdir='modules', encoding=None):
|
||||
"Open a file from the root directory, using subdir folder"
|
||||
path = find_path(name, subdir)
|
||||
path = find_path(name, subdir, _test=None)
|
||||
return io.open(path, mode, encoding=encoding)
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ def find_path(name, subdir='modules', _test=os.path.isfile):
|
||||
else:
|
||||
path = secure_join(root_path, name)
|
||||
|
||||
if _test(path):
|
||||
if not _test or _test(path):
|
||||
return path
|
||||
else:
|
||||
raise FileNotFoundError("No such file or directory: %r" % name)
|
||||
|
||||
Reference in new issue
Block a user