From 3dba4e7697796961c156e7be47965d78b0c5e7d1 Mon Sep 17 00:00:00 2001 From: ut003165 Date: Thu, 20 Jul 2023 17:12:19 +0800 Subject: [PATCH] Variable optimization for absolute path checking methods The optimized method avoids creating unnecessary intermediate variable abs_path and directly processes on the original variable file_path, making the code more concise. Signed-off-by: wulei01 --- avocado/core/utils/path.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/avocado/core/utils/path.py b/avocado/core/utils/path.py index 8037bdd5a5..50800fde81 100644 --- a/avocado/core/utils/path.py +++ b/avocado/core/utils/path.py @@ -29,10 +29,8 @@ def system_wide_or_base_path(file_path): :type file_path: str :rtype: str """ - if os.path.isabs(file_path): - abs_path = file_path - else: - abs_path = os.path.join(os.path.sep, file_path) - if os.path.exists(abs_path): - return abs_path - return prepend_base_path(file_path) + if not os.path.isabs(file_path): + file_path = os.path.join(os.path.sep, file_path) + if not os.path.exists(file_path): + return prepend_base_path(file_path) + return file_path