2525import subprocess
2626import sys
2727import time
28+ import typing
2829import unicodedata
29- from typing import (
30- TYPE_CHECKING ,
31- Any ,
32- NoReturn ,
33- )
3430
3531import humanize
3632
4642 get_virtualenv ,
4743)
4844
49- if TYPE_CHECKING :
45+ if typing . TYPE_CHECKING :
5046 import argparse
5147 from collections .abc import (
5248 Callable ,
5753 Sequence ,
5854 )
5955 from types import TracebackType
60- from typing import IO
56+ from typing import (
57+ IO ,
58+ Any ,
59+ Literal ,
60+ NoReturn ,
61+ )
6162
6263 from nox ._decorators import Func
6364 from nox .command import ExternalType
@@ -279,7 +280,7 @@ def install_and_run_script(
279280 stderr : int | IO [str ] | None = subprocess .STDOUT ,
280281 interrupt_timeout : float | None = DEFAULT_INTERRUPT_TIMEOUT ,
281282 terminate_timeout : float | None = DEFAULT_TERMINATE_TIMEOUT ,
282- ) -> Any | None :
283+ ) -> str | bool | None :
283284 """
284285 Install dependencies and run a Python script.
285286 """
@@ -342,6 +343,54 @@ def _run_func(self, func: Callable[..., Any], args: Iterable[Any]) -> Any:
342343 logger .exception (f"Function { func !r} raised { e !r} ." )
343344 raise nox .command .CommandFailed () from e
344345
346+ @typing .overload
347+ def run (
348+ self ,
349+ * args : str | os .PathLike [str ],
350+ env : Mapping [str , str | None ] | None = None ,
351+ include_outer_env : bool = True ,
352+ silent : Literal [False ] = ...,
353+ success_codes : Iterable [int ] | None = None ,
354+ log : bool = True ,
355+ external : ExternalType | None = None ,
356+ stdout : int | IO [str ] | None = None ,
357+ stderr : int | IO [str ] | None = subprocess .STDOUT ,
358+ interrupt_timeout : float | None = DEFAULT_INTERRUPT_TIMEOUT ,
359+ terminate_timeout : float | None = DEFAULT_TERMINATE_TIMEOUT ,
360+ ) -> bool | None : ...
361+
362+ @typing .overload
363+ def run (
364+ self ,
365+ * args : str | os .PathLike [str ],
366+ env : Mapping [str , str | None ] | None = None ,
367+ include_outer_env : bool = True ,
368+ silent : Literal [True ],
369+ success_codes : Iterable [int ] | None = None ,
370+ log : bool = True ,
371+ external : ExternalType | None = None ,
372+ stdout : int | IO [str ] | None = None ,
373+ stderr : int | IO [str ] | None = subprocess .STDOUT ,
374+ interrupt_timeout : float | None = DEFAULT_INTERRUPT_TIMEOUT ,
375+ terminate_timeout : float | None = DEFAULT_TERMINATE_TIMEOUT ,
376+ ) -> str | None : ...
377+
378+ @typing .overload
379+ def run (
380+ self ,
381+ * args : str | os .PathLike [str ],
382+ env : Mapping [str , str | None ] | None = None ,
383+ include_outer_env : bool = True ,
384+ silent : bool ,
385+ success_codes : Iterable [int ] | None = None ,
386+ log : bool = True ,
387+ external : ExternalType | None = None ,
388+ stdout : int | IO [str ] | None = None ,
389+ stderr : int | IO [str ] | None = subprocess .STDOUT ,
390+ interrupt_timeout : float | None = DEFAULT_INTERRUPT_TIMEOUT ,
391+ terminate_timeout : float | None = DEFAULT_TERMINATE_TIMEOUT ,
392+ ) -> str | bool | None : ...
393+
345394 def run (
346395 self ,
347396 * args : str | os .PathLike [str ],
@@ -355,7 +404,7 @@ def run(
355404 stderr : int | IO [str ] | None = subprocess .STDOUT ,
356405 interrupt_timeout : float | None = DEFAULT_INTERRUPT_TIMEOUT ,
357406 terminate_timeout : float | None = DEFAULT_TERMINATE_TIMEOUT ,
358- ) -> Any | None :
407+ ) -> str | bool | None :
359408 """Run a command.
360409
361410 Commands must be specified as a list of strings, for example::
@@ -495,7 +544,7 @@ def run_install(
495544 stderr : int | IO [str ] | None = subprocess .STDOUT ,
496545 interrupt_timeout : float | None = DEFAULT_INTERRUPT_TIMEOUT ,
497546 terminate_timeout : float | None = DEFAULT_TERMINATE_TIMEOUT ,
498- ) -> Any | None :
547+ ) -> str | bool | None :
499548 """Run a command in the install step.
500549
501550 This is a variant of :meth:`run` that runs even in the presence of
@@ -578,7 +627,7 @@ def run_always(
578627 stderr : int | IO [str ] | None = subprocess .STDOUT ,
579628 interrupt_timeout : float | None = DEFAULT_INTERRUPT_TIMEOUT ,
580629 terminate_timeout : float | None = DEFAULT_TERMINATE_TIMEOUT ,
581- ) -> Any | None :
630+ ) -> str | bool | None :
582631 """This is an alias to ``run_install``, which better describes the use case.
583632
584633 :meta private:
@@ -611,7 +660,7 @@ def _run(
611660 stderr : int | IO [str ] | None ,
612661 interrupt_timeout : float | None ,
613662 terminate_timeout : float | None ,
614- ) -> Any :
663+ ) -> str | bool :
615664 """Like run(), except that it runs even if --install-only is provided."""
616665 # Legacy support - run a function given.
617666 if callable (args [0 ]):
@@ -1167,7 +1216,7 @@ def execute(self) -> Result:
11671216 logger .error (f"Session { self .friendly_name } interrupted." )
11681217 raise
11691218
1170- except Exception as exc :
1219+ except Exception as exc : # noqa: BLE001
11711220 logger .exception (f"Session { self .friendly_name } raised exception { exc !r} " )
11721221 self .result = Result (
11731222 self , Status .FAILED , duration = time .perf_counter () - start
0 commit comments