From 4de2a904f96425df67904424ffba1b3b108eae8d Mon Sep 17 00:00:00 2001 From: Dan Farnsworth Date: Tue, 2 Aug 2022 16:47:56 -0600 Subject: [PATCH] Found inconsitency with __builtin__ module, when it changes based on module or main --- devlab_bench/helpers/common.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/devlab_bench/helpers/common.py b/devlab_bench/helpers/common.py index 458547a..ae38b1c 100644 --- a/devlab_bench/helpers/common.py +++ b/devlab_bench/helpers/common.py @@ -19,7 +19,9 @@ #Python2/3 compatibility try: #Python2 - text_input = globals()['__builtins__'].raw_input #pylint: disable=invalid-name + ## NOTE __builtins__ is a "dict" when used inside a module, otherwise in "__main__" it is a module. + ## See the "implementation detail" at the bottom of: https://docs.python.org/3.8/library/builtins.html + text_input = __builtins__['raw_input'] #pylint: disable=invalid-name from pipes import quote #pylint: disable=unused-import try: from pathlib2 import Path #pylint: disable=unused-import @@ -34,7 +36,7 @@ def home(self=None): #pylint: disable=bad-staticmethod-argument,unused-argument Return the expanded path to the user's home """ return os.path.expanduser('~') -except AttributeError: +except KeyError: #Python3 text_input = input #pylint: disable=invalid-name quote = shlex.quote #pylint: disable=invalid-name