From 810644614022d8835b7d78d1afe074387605e1a3 Mon Sep 17 00:00:00 2001 From: Adrian Garcia Badaracco <1755071+adriangb@users.noreply.github.com> Date: Wed, 16 Mar 2022 19:27:15 -0500 Subject: postpone referencing sys.modules["__main"] in click.utils._detect_program_name --- src/click/utils.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/click/utils.py b/src/click/utils.py index 467b7b6..8283788 100644 --- a/src/click/utils.py +++ b/src/click/utils.py @@ -475,7 +475,7 @@ class PacifyFlushWrapper: def _detect_program_name( - path: t.Optional[str] = None, _main: ModuleType = sys.modules["__main__"] + path: t.Optional[str] = None, _main: t.Optional[ModuleType] = None ) -> str: """Determine the command used to run the program, for use in help text. If a file or entry point was executed, the file name is @@ -497,6 +497,9 @@ def _detect_program_name( :meta private: """ + if _main is None: + _main = sys.modules["__main__"] + if not path: path = sys.argv[0] -- cgit v1.2.1