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:
Cédric Krier committed 2024-05-01 20:03:17 +02:00
1 parent 270851ad9f
commit 9363eafb87
1 file changed
+2 -2
+2 -2
View File
@@ -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)