11from __future__ import annotations
22
33import subprocess
4+ from collections .abc import Iterable , Mapping , Sequence
45from dataclasses import dataclass
5- from typing import Callable , Dict , List , Sequence
6+ from typing import Callable , Dict , List # noqa: TID251
67
78import bashlex
89
910# a function that takes a command and the environment, and returns the result
1011EnvironmentExecutor = Callable [[List [str ], Dict [str , str ]], str ]
1112
1213
13- def local_environment_executor (command : list [str ], env : dict [str , str ]) -> str :
14+ def local_environment_executor (command : Sequence [str ], env : Mapping [str , str ]) -> str :
1415 return subprocess .run (command , env = env , text = True , stdout = subprocess .PIPE , check = True ).stdout
1516
1617
@@ -22,7 +23,7 @@ class NodeExecutionContext:
2223
2324
2425def evaluate (
25- value : str , environment : dict [str , str ], executor : EnvironmentExecutor | None = None
26+ value : str , environment : Mapping [str , str ], executor : EnvironmentExecutor | None = None
2627) -> str :
2728 if not value :
2829 # empty string evaluates to empty string
@@ -40,7 +41,9 @@ def evaluate(
4041 return evaluate_node (
4142 value_word_node ,
4243 context = NodeExecutionContext (
43- environment = environment , input = value , executor = executor or local_environment_executor
44+ environment = dict (environment ),
45+ input = value ,
46+ executor = executor or local_environment_executor ,
4447 ),
4548 )
4649
@@ -105,7 +108,7 @@ def evaluate_nodes_as_compound_command(
105108
106109
107110def evaluate_nodes_as_simple_command (
108- nodes : list [bashlex .ast .node ], context : NodeExecutionContext
111+ nodes : Iterable [bashlex .ast .node ], context : NodeExecutionContext
109112) -> str :
110113 command = [evaluate_node (part , context = context ) for part in nodes ]
111114 return context .executor (command , context .environment )
0 commit comments