From 60ea5bee832cf1be454c2264c069d46555eb36b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tuna=20Alika=C5=9Fifo=C4=9Flu?= Date: Mon, 17 Mar 2025 20:39:04 +0300 Subject: [PATCH] fix: correct fallback with no key no `.env` file Fixes the fall back behavior when no key is provided and no `.env` file is found. The previous implementation was raising an exception due to opening a file that does not exist. Fixes: #27 --- src/dotenv_vault/main.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/dotenv_vault/main.py b/src/dotenv_vault/main.py index 2ef436b..221dfed 100644 --- a/src/dotenv_vault/main.py +++ b/src/dotenv_vault/main.py @@ -65,7 +65,8 @@ def load_dotenv( ) else: dotenv_path = dotenv.find_dotenv(usecwd=True) - stream = open(dotenv_path) if not stream else stream + if not stream: + stream = open(dotenv_path) if dotenv_path else None return dotenv.load_dotenv( stream=stream, verbose=verbose,