From 3d03098a97ddc6a908aa4a50c2ef7381f8297d0a Mon Sep 17 00:00:00 2001 From: Markus Heidelberg Date: Tue, 20 Jan 2026 14:16:17 +0100 Subject: [PATCH] Abort if the instance folder cannot be created According to the comment, the instance folder should exist in any case. But a PermissionError was ignored silently. Since Python 3.9 is the minimum required version, it is safe to use "exist_ok" added in Python 3.2 and avoid exception handling. --- docs/tutorial/factory.rst | 5 +---- examples/tutorial/flaskr/__init__.py | 5 +---- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/docs/tutorial/factory.rst b/docs/tutorial/factory.rst index 39febd13..381477f9 100644 --- a/docs/tutorial/factory.rst +++ b/docs/tutorial/factory.rst @@ -56,10 +56,7 @@ directory should be treated as a package. app.config.from_mapping(test_config) # ensure the instance folder exists - try: - os.makedirs(app.instance_path) - except OSError: - pass + os.makedirs(app.instance_path, exist_ok=True) # a simple page that says hello @app.route('/hello') diff --git a/examples/tutorial/flaskr/__init__.py b/examples/tutorial/flaskr/__init__.py index e35934d6..ab96e719 100644 --- a/examples/tutorial/flaskr/__init__.py +++ b/examples/tutorial/flaskr/__init__.py @@ -21,10 +21,7 @@ def create_app(test_config=None): app.config.update(test_config) # ensure the instance folder exists - try: - os.makedirs(app.instance_path) - except OSError: - pass + os.makedirs(app.instance_path, exist_ok=True) @app.route("/hello") def hello():