chore: use from __future__ import annotations

This commit is contained in:
mayeut
2022-07-19 07:47:45 +02:00
parent 054230e01b
commit 6d27f05c7c
71 changed files with 285 additions and 166 deletions
+7 -5
View File
@@ -1,6 +1,8 @@
from __future__ import annotations
import subprocess
from dataclasses import dataclass
from typing import Callable, Dict, List, Optional, Sequence
from typing import Callable, Dict, List, Sequence
import bashlex
@@ -8,19 +10,19 @@ import bashlex
EnvironmentExecutor = Callable[[List[str], Dict[str, str]], str]
def local_environment_executor(command: List[str], env: Dict[str, str]) -> str:
def local_environment_executor(command: list[str], env: dict[str, str]) -> str:
return subprocess.run(command, env=env, text=True, stdout=subprocess.PIPE, check=True).stdout
@dataclass(frozen=True)
class NodeExecutionContext:
environment: Dict[str, str]
environment: dict[str, str]
input: str
executor: EnvironmentExecutor
def evaluate(
value: str, environment: Dict[str, str], executor: Optional[EnvironmentExecutor] = None
value: str, environment: dict[str, str], executor: EnvironmentExecutor | None = None
) -> str:
if not value:
# empty string evaluates to empty string
@@ -101,7 +103,7 @@ def evaluate_nodes_as_compound_command(
def evaluate_nodes_as_simple_command(
nodes: List[bashlex.ast.node], context: NodeExecutionContext
nodes: list[bashlex.ast.node], context: NodeExecutionContext
) -> str:
command = [evaluate_node(part, context=context) for part in nodes]
return context.executor(command, context.environment)