diff --git a/poethepoet/app.py b/poethepoet/app.py index 058b9f9b0..0b98e7c79 100644 --- a/poethepoet/app.py +++ b/poethepoet/app.py @@ -173,7 +173,8 @@ def print_help( from .task.args import PoeTaskArgs if isinstance(error, str): - error == PoeException(error) + error = PoeException(error) + tasks_help: Dict[str, Tuple[str, Sequence[Tuple[Tuple[str, ...], str]]]] = { task_name: ( ( @@ -185,4 +186,5 @@ def print_help( ) for task_name, content in self.config.tasks.items() } - self.ui.print_help(tasks=tasks_help, info=info, error=error) # type: ignore + + self.ui.print_help(tasks=tasks_help, info=info, error=error) diff --git a/poethepoet/exceptions.py b/poethepoet/exceptions.py index 0312d99f1..68d916e1e 100644 --- a/poethepoet/exceptions.py +++ b/poethepoet/exceptions.py @@ -1,4 +1,9 @@ +from typing import Optional + + class PoeException(RuntimeError): + cause: Optional[str] + def __init__(self, msg, *args): self.msg = msg self.cause = args[0].args[0] if args else None @@ -14,6 +19,8 @@ class ExpressionParseError(PoeException): class ExecutionError(RuntimeError): + cause: Optional[str] + def __init__(self, msg, *args): self.msg = msg self.cause = args[0].args[0] if args else None diff --git a/poethepoet/helpers/python.py b/poethepoet/helpers/python.py index 1d514e657..6331100d6 100644 --- a/poethepoet/helpers/python.py +++ b/poethepoet/helpers/python.py @@ -301,7 +301,7 @@ def _get_name_source_segment(source: str, node: ast.Name): performant in common cases. """ if sys.version_info.minor >= 8: - return ast.get_source_segment(source, node) # type: ignore + return ast.get_source_segment(source, node) partial_result = ( re.split(r"(?:\r\n|\r|\n)", source)[node.lineno - 1] diff --git a/poethepoet/ui.py b/poethepoet/ui.py index ea11053a1..537f2b793 100644 --- a/poethepoet/ui.py +++ b/poethepoet/ui.py @@ -3,7 +3,7 @@ from typing import IO, TYPE_CHECKING, List, Mapping, Optional, Sequence, Tuple, Union from .__version__ import __version__ -from .exceptions import PoeException +from .exceptions import ExecutionError, PoeException if TYPE_CHECKING: from argparse import ArgumentParser, Namespace @@ -142,7 +142,9 @@ def set_default_verbosity(self, default_verbosity: int): def print_help( self, - tasks: Optional[Mapping[str, Tuple[str, Sequence[Tuple[str, str]]]]] = None, + tasks: Optional[ + Mapping[str, Tuple[str, Sequence[Tuple[Tuple[str, ...], str]]]] + ] = None, info: Optional[str] = None, error: Optional[PoeException] = None, ): @@ -165,9 +167,10 @@ def print_help( if error: # TODO: send this to stderr instead? - result.append([f"Error: {error.msg} "]) + error_line = [f"Error: {error.msg} "] if error.cause: - result[-1].append(f" From: {error.cause} ") # type: ignore + error_line.append(f" From: {error.cause} ") + result.append(error_line) if verbosity >= 0: # Use argparse for usage summary @@ -233,10 +236,10 @@ def print_msg(self, message: str, verbosity=0, end="\n"): if verbosity <= self.verbosity: self._print(message, end=end) - def print_error(self, error: Exception): - self._print(f"Error: {error.msg} ") # type: ignore - if error.cause: # type: ignore - self._print(f" From: {error.cause} ") # type: ignore + def print_error(self, error: Union[PoeException, ExecutionError]): + self._print(f"Error: {error.msg} ") + if error.cause: + self._print(f" From: {error.cause} ") def print_version(self): if self.verbosity >= 0: diff --git a/poethepoet/virtualenv.py b/poethepoet/virtualenv.py index 56887cf56..11a48dac7 100644 --- a/poethepoet/virtualenv.py +++ b/poethepoet/virtualenv.py @@ -70,7 +70,9 @@ def valid(self) -> bool: and bin_dir.joinpath("python").is_file() and bool( next( - self.path.glob(os.path.sep.join(("lib", "python3*", "site-packages"))), # type: ignore + self.path.glob( + os.path.sep.join(("lib", "python3*", "site-packages")) + ), False, ) )