70
70
71
71
72
72
if TYPE_CHECKING :
73
- from _pytest .assertions .rewrite import AssertionRewritingHook
73
+ from _pytest .assertion .rewrite import AssertionRewritingHook
74
74
from _pytest .cacheprovider import Cache
75
75
from _pytest .terminal import TerminalReporter
76
76
@@ -273,9 +273,11 @@ def directory_arg(path: str, optname: str) -> str:
273
273
"faulthandler" ,
274
274
)
275
275
276
- builtin_plugins = set (default_plugins )
277
- builtin_plugins .add ("pytester" )
278
- builtin_plugins .add ("pytester_assertions" )
276
+ builtin_plugins = {
277
+ * default_plugins ,
278
+ "pytester" ,
279
+ "pytester_assertions" ,
280
+ }
279
281
280
282
281
283
def get_config (
@@ -397,7 +399,8 @@ class PytestPluginManager(PluginManager):
397
399
"""
398
400
399
401
def __init__ (self ) -> None :
400
- import _pytest .assertion
402
+ from _pytest .assertion import DummyRewriteHook
403
+ from _pytest .assertion import RewriteHook
401
404
402
405
super ().__init__ ("pytest" )
403
406
@@ -443,7 +446,7 @@ def __init__(self) -> None:
443
446
self .enable_tracing ()
444
447
445
448
# Config._consider_importhook will set a real object if required.
446
- self .rewrite_hook = _pytest . assertion . DummyRewriteHook ()
449
+ self .rewrite_hook : RewriteHook = DummyRewriteHook ()
447
450
# Used to know when we are importing conftests after the pytest_configure stage.
448
451
self ._configured = False
449
452
@@ -469,21 +472,21 @@ def parse_hookimpl_opts(
469
472
if not inspect .isroutine (method ):
470
473
return None
471
474
# Collect unmarked hooks as long as they have the `pytest_' prefix.
472
- return _get_legacy_hook_marks ( # type: ignore[return-value]
475
+ legacy = _get_legacy_hook_marks (
473
476
method , "impl" , ("tryfirst" , "trylast" , "optionalhook" , "hookwrapper" )
474
477
)
478
+ return cast (HookimplOpts , legacy )
475
479
476
480
def parse_hookspec_opts (self , module_or_class , name : str ) -> HookspecOpts | None :
477
481
""":meta private:"""
478
482
opts = super ().parse_hookspec_opts (module_or_class , name )
479
483
if opts is None :
480
484
method = getattr (module_or_class , name )
481
485
if name .startswith ("pytest_" ):
482
- opts = _get_legacy_hook_marks ( # type: ignore[assignment]
483
- method ,
484
- "spec" ,
485
- ("firstresult" , "historic" ),
486
+ legacy = _get_legacy_hook_marks (
487
+ method , "spec" , ("firstresult" , "historic" )
486
488
)
489
+ opts = cast (HookspecOpts , legacy )
487
490
return opts
488
491
489
492
def register (self , plugin : _PluggyPlugin , name : str | None = None ) -> str | None :
@@ -1581,7 +1584,7 @@ def addinivalue_line(self, name: str, line: str) -> None:
1581
1584
assert isinstance (x , list )
1582
1585
x .append (line ) # modifies the cached list inline
1583
1586
1584
- def getini (self , name : str ):
1587
+ def getini (self , name : str ) -> Any :
1585
1588
"""Return configuration value from an :ref:`ini file <configfiles>`.
1586
1589
1587
1590
If a configuration value is not defined in an
@@ -1725,7 +1728,7 @@ def _get_override_ini_value(self, name: str) -> str | None:
1725
1728
value = user_ini_value
1726
1729
return value
1727
1730
1728
- def getoption (self , name : str , default = notset , skip : bool = False ):
1731
+ def getoption (self , name : str , default : Any = notset , skip : bool = False ):
1729
1732
"""Return command line option value.
1730
1733
1731
1734
:param name: Name of the option. You may also specify
0 commit comments