1
+ # mypy: check_untyped_defs
1
2
""" command line options, ini-file and conftest.py processing. """
2
3
import argparse
3
4
import copy
45
46
if False : # TYPE_CHECKING
46
47
from typing import Type
47
48
49
+ from .argparsing import Argument
50
+
48
51
49
52
hookimpl = HookimplMarker ("pytest" )
50
53
hookspec = HookspecMarker ("pytest" )
@@ -679,7 +682,7 @@ class InvocationParams:
679
682
plugins = attr .ib ()
680
683
dir = attr .ib (type = Path )
681
684
682
- def __init__ (self , pluginmanager , * , invocation_params = None ):
685
+ def __init__ (self , pluginmanager , * , invocation_params = None ) -> None :
683
686
from .argparsing import Parser , FILE_OR_DIR
684
687
685
688
if invocation_params is None :
@@ -792,19 +795,20 @@ def fromdictargs(cls, option_dict, args):
792
795
config .pluginmanager .consider_pluginarg (x )
793
796
return config
794
797
795
- def _processopt (self , opt ):
796
- for name in opt ._short_opts + opt ._long_opts :
797
- self ._opt2dest [name ] = opt .dest
798
+ def _processopt (self , opt : "Argument" ) -> None :
799
+ if opt .dest :
800
+ for name in opt ._short_opts + opt ._long_opts :
801
+ self ._opt2dest [name ] = opt .dest
798
802
799
- if hasattr (opt , "default" ) and opt . dest :
800
- if not hasattr (self .option , opt .dest ):
801
- setattr (self .option , opt .dest , opt .default )
803
+ if hasattr (opt , "default" ):
804
+ if not hasattr (self .option , opt .dest ):
805
+ setattr (self .option , opt .dest , opt .default )
802
806
803
807
@hookimpl (trylast = True )
804
808
def pytest_load_initial_conftests (self , early_config ):
805
809
self .pluginmanager ._set_initial_conftests (early_config .known_args_namespace )
806
810
807
- def _initini (self , args ) -> None :
811
+ def _initini (self , args : Sequence [ str ] ) -> None :
808
812
ns , unknown_args = self ._parser .parse_known_and_unknown_args (
809
813
args , namespace = copy .copy (self .option )
810
814
)
@@ -821,7 +825,7 @@ def _initini(self, args) -> None:
821
825
self ._parser .addini ("minversion" , "minimally required pytest version" )
822
826
self ._override_ini = ns .override_ini or ()
823
827
824
- def _consider_importhook (self , args ) :
828
+ def _consider_importhook (self , args : Sequence [ str ]) -> None :
825
829
"""Install the PEP 302 import hook if using assertion rewriting.
826
830
827
831
Needs to parse the --assert=<mode> option from the commandline
@@ -861,19 +865,19 @@ def _mark_plugins_for_rewrite(self, hook):
861
865
for name in _iter_rewritable_modules (package_files ):
862
866
hook .mark_rewrite (name )
863
867
864
- def _validate_args (self , args , via ) :
868
+ def _validate_args (self , args : List [ str ] , via : str ) -> List [ str ] :
865
869
"""Validate known args."""
866
- self ._parser ._config_source_hint = via
870
+ self ._parser ._config_source_hint = via # type: ignore
867
871
try :
868
872
self ._parser .parse_known_and_unknown_args (
869
873
args , namespace = copy .copy (self .option )
870
874
)
871
875
finally :
872
- del self ._parser ._config_source_hint
876
+ del self ._parser ._config_source_hint # type: ignore
873
877
874
878
return args
875
879
876
- def _preparse (self , args , addopts = True ):
880
+ def _preparse (self , args : List [ str ] , addopts : bool = True ) -> None :
877
881
if addopts :
878
882
env_addopts = os .environ .get ("PYTEST_ADDOPTS" , "" )
879
883
if len (env_addopts ):
@@ -937,7 +941,7 @@ def _checkversion(self):
937
941
)
938
942
)
939
943
940
- def parse (self , args , addopts = True ):
944
+ def parse (self , args : List [ str ] , addopts : bool = True ) -> None :
941
945
# parse given cmdline arguments into this config object.
942
946
assert not hasattr (
943
947
self , "args"
@@ -948,7 +952,7 @@ def parse(self, args, addopts=True):
948
952
self ._preparse (args , addopts = addopts )
949
953
# XXX deprecated hook:
950
954
self .hook .pytest_cmdline_preparse (config = self , args = args )
951
- self ._parser .after_preparse = True
955
+ self ._parser .after_preparse = True # type: ignore
952
956
try :
953
957
args = self ._parser .parse_setoption (
954
958
args , self .option , namespace = self .option
0 commit comments