Skip to content
Myr

Merge pull request #2215 from adriangb/fix-anyio

Before adoption: this commit came in with the history the project adopted, so no landing records it.

postpone referencing sys.modules["__main__"]

authored by David Lord · committed by GitHub · parents 5ba2320, 38e6174 · Browse files · 2 files+7 added−12 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+7 added−12 removed

  • tests:+3 added−11 removed
  • other:+4 added−1 removed

2 files+7 added−12 removed

modified:src/click/utils.py+4 added-1 removed
473 unmodified lines
474 return getattr(self.wrapped, attr)475476477def _detect_program_name(478 path: t.Optional[str] = None, _main: ModuleType = sys.modules["__main__"]478 path: t.Optional[str] = None, _main: t.Optional[ModuleType] = None479) -> str:480 """Determine the command used to run the program, for use in help481 text. If a file or entry point was executed, the file name is482 returned. If ``python -m`` was used to execute a module or package,
13 unmodified lines
496 Based on command args detection in the Werkzeug reloader.497498 :meta private:499 """500 if _main is None:501 _main = sys.modules["__main__"]502503 if not path:504 path = sys.argv[0]505506 # The value of __package__ indicates how Python was called. It may
74 unmodified lines
modified:tests/test_utils.py+3 added-11 removed
442 unmodified lines
443 [444 ("example.py", None, "example.py"),445 (str(pathlib.Path("/foo/bar/example.py")), None, "example.py"),446 ("example", None, "example"),447 (448 str(pathlib.Path("example/__main__.py")),449 MockMain(".example"),450 "python -m example",451 ),452 (453 str(pathlib.Path("example/cli.py")),454 MockMain(".example"),455 "python -m example.cli",456 ),447 (str(pathlib.Path("example/__main__.py")), "example", "python -m example"),448 (str(pathlib.Path("example/cli.py")), "example", "python -m example.cli"),449 ],450)451def test_detect_program_name(path, main, expected):460 assert click.utils._detect_program_name(path, _main=main) == expected452 assert click.utils._detect_program_name(path, _main=MockMain(main)) == expected453454455def test_expand_args(monkeypatch):456 user = os.path.expanduser("~")
44 unmodified lines