33
44from __future__ import annotations
55
6- from argparse import Action
6+ import argparse
77from collections .abc import Generator
8+ from collections .abc import Sequence
89import os
910import sys
11+ from typing import Any
1012
1113from _pytest .config import Config
1214from _pytest .config import ExitCode
1315from _pytest .config import PrintHelp
16+ from _pytest .config .argparsing import MyOptionParser
1417from _pytest .config .argparsing import Parser
1518from _pytest .terminal import TerminalReporter
1619import pytest
1720
1821
19- class HelpAction (Action ):
22+ class HelpAction (argparse . Action ):
2023 """An argparse Action that will raise an exception in order to skip the
2124 rest of the argument parsing when --help is passed.
2225
@@ -26,20 +29,29 @@ class HelpAction(Action):
2629 implemented by raising SystemExit.
2730 """
2831
29- def __init__ (self , option_strings , dest = None , default = False , help = None ):
32+ def __init__ (
33+ self , option_strings : Sequence [str ], dest : str , * , help : str | None = None
34+ ) -> None :
3035 super ().__init__ (
3136 option_strings = option_strings ,
3237 dest = dest ,
33- const = True ,
34- default = default ,
3538 nargs = 0 ,
39+ const = True ,
40+ default = False ,
3641 help = help ,
3742 )
3843
39- def __call__ (self , parser , namespace , values , option_string = None ):
44+ def __call__ (
45+ self ,
46+ parser : argparse .ArgumentParser ,
47+ namespace : argparse .Namespace ,
48+ values : str | Sequence [Any ] | None ,
49+ option_string : str | None = None ,
50+ ) -> None :
4051 setattr (namespace , self .dest , self .const )
4152
4253 # We should only skip the rest of the parsing after preparse is done.
54+ assert isinstance (parser , MyOptionParser )
4355 if getattr (parser ._parser , "after_preparse" , False ):
4456 raise PrintHelp
4557
0 commit comments