File tree Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -545,6 +545,13 @@ def __repr__(self) -> str:
545545 return f"Install or Uninstall shell completion:\n { _get_completion_help ()} "
546546
547547 if sys .version_info >= (3 , 14 ):
548+ # Python 3.14+ adds help message validation via ArgumentParser._check_help,
549+ # which calls formatter._expand_help(action) to validate that action.help
550+ # is a string that can be used in string formatting (e.g., "text %(prog)s").
551+ # This breaks our LazyCompletionHelp because `_expand_help` expects an actual
552+ # string.
553+ # It is safe to disable this validation temporarily because LazyCompletionHelp.
554+ # __repr__() returns a plain string (no % formatting)
548555 original_check_help = argparse .ArgumentParser ._check_help # type: ignore
549556 argparse .ArgumentParser ._check_help = ( # type: ignore
550557 lambda self , action : None
Original file line number Diff line number Diff line change @@ -841,6 +841,24 @@ def test_help(
841841 assert_text_same (result , expected .format (script = script ))
842842
843843
844+ def test_shell_completion_help (tmpdir : Path ) -> None :
845+ """Test that --shell-completion --help works (regression test for Python 3.14+ argparse)."""
846+ # This test ensures that the LazyCompletionHelp workaround in utils.py works correctly
847+ # In Python 3.14+, argparse validates that help is a string, but we use a lazy callable
848+ # The workaround temporarily disables _check_help validation
849+ cmd = [
850+ "examples/tutorials/basic/your_first_hydra_app/1_simple_cli/my_app.py" ,
851+ f'hydra.run.dir="{ str (tmpdir )} "' ,
852+ "hydra.job.chdir=True" ,
853+ "--shell-completion" ,
854+ "--help" ,
855+ ]
856+ result , _err = run_python_script (cmd )
857+ # When both flags are present, --help takes precedence and shows help text
858+ assert "powered by hydra" in result .lower ()
859+ assert not _err
860+
861+
844862@mark .parametrize (
845863 "overrides,expected" ,
846864 [
You can’t perform that action at this time.
0 commit comments