summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Garcia Badaracco <1755071+adriangb@users.noreply.github.com>2022-03-16 19:27:15 -0500
committerDavid Lord <davidism@gmail.com>2022-03-17 12:05:35 -0700
commit810644614022d8835b7d78d1afe074387605e1a3 (patch)
treebe110c0214f6d56172a9429276b50090231ac741
parent5ba2320454065a78dbb4176e582ab21c990d358c (diff)
downloadclick-810644614022d8835b7d78d1afe074387605e1a3.tar.gz
postpone referencing sys.modules["__main"] in click.utils._detect_program_name
-rw-r--r--src/click/utils.py5
1 files changed, 4 insertions, 1 deletions
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]