7070
7171
7272if TYPE_CHECKING :
73- from _pytest .assertions .rewrite import AssertionRewritingHook
73+ from _pytest .assertion .rewrite import AssertionRewritingHook
7474 from _pytest .cacheprovider import Cache
7575 from _pytest .terminal import TerminalReporter
7676
@@ -273,9 +273,11 @@ def directory_arg(path: str, optname: str) -> str:
273273 "faulthandler" ,
274274)
275275
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+ }
279281
280282
281283def get_config (
@@ -397,7 +399,8 @@ class PytestPluginManager(PluginManager):
397399 """
398400
399401 def __init__ (self ) -> None :
400- import _pytest .assertion
402+ from _pytest .assertion import DummyRewriteHook
403+ from _pytest .assertion import RewriteHook
401404
402405 super ().__init__ ("pytest" )
403406
@@ -443,7 +446,7 @@ def __init__(self) -> None:
443446 self .enable_tracing ()
444447
445448 # Config._consider_importhook will set a real object if required.
446- self .rewrite_hook = _pytest . assertion . DummyRewriteHook ()
449+ self .rewrite_hook : RewriteHook = DummyRewriteHook ()
447450 # Used to know when we are importing conftests after the pytest_configure stage.
448451 self ._configured = False
449452
@@ -469,21 +472,21 @@ def parse_hookimpl_opts(
469472 if not inspect .isroutine (method ):
470473 return None
471474 # 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 (
473476 method , "impl" , ("tryfirst" , "trylast" , "optionalhook" , "hookwrapper" )
474477 )
478+ return cast (HookimplOpts , legacy )
475479
476480 def parse_hookspec_opts (self , module_or_class , name : str ) -> HookspecOpts | None :
477481 """:meta private:"""
478482 opts = super ().parse_hookspec_opts (module_or_class , name )
479483 if opts is None :
480484 method = getattr (module_or_class , name )
481485 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" )
486488 )
489+ opts = cast (HookspecOpts , legacy )
487490 return opts
488491
489492 def register (self , plugin : _PluggyPlugin , name : str | None = None ) -> str | None :
@@ -1581,7 +1584,7 @@ def addinivalue_line(self, name: str, line: str) -> None:
15811584 assert isinstance (x , list )
15821585 x .append (line ) # modifies the cached list inline
15831586
1584- def getini (self , name : str ):
1587+ def getini (self , name : str ) -> Any :
15851588 """Return configuration value from an :ref:`ini file <configfiles>`.
15861589
15871590 If a configuration value is not defined in an
@@ -1725,7 +1728,7 @@ def _get_override_ini_value(self, name: str) -> str | None:
17251728 value = user_ini_value
17261729 return value
17271730
1728- def getoption (self , name : str , default = notset , skip : bool = False ):
1731+ def getoption (self , name : str , default : Any = notset , skip : bool = False ):
17291732 """Return command line option value.
17301733
17311734 :param name: Name of the option. You may also specify
0 commit comments