11from __future__ import annotations
22
33import subprocess
4- from collections .abc import Sequence
4+ from collections .abc import Iterable , Mapping , Sequence
55from dataclasses import dataclass
66from typing import Callable , Dict , List # noqa: TID251
77
1111EnvironmentExecutor = Callable [[List [str ], Dict [str , str ]], str ]
1212
1313
14- 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 :
1515 return subprocess .run (command , env = env , text = True , stdout = subprocess .PIPE , check = True ).stdout
1616
1717
@@ -23,7 +23,7 @@ class NodeExecutionContext:
2323
2424
2525def evaluate (
26- value : str , environment : dict [str , str ], executor : EnvironmentExecutor | None = None
26+ value : str , environment : Mapping [str , str ], executor : EnvironmentExecutor | None = None
2727) -> str :
2828 if not value :
2929 # empty string evaluates to empty string
@@ -41,7 +41,9 @@ def evaluate(
4141 return evaluate_node (
4242 value_word_node ,
4343 context = NodeExecutionContext (
44- environment = environment , input = value , executor = executor or local_environment_executor
44+ environment = dict (environment ),
45+ input = value ,
46+ executor = executor or local_environment_executor ,
4547 ),
4648 )
4749
@@ -106,7 +108,7 @@ def evaluate_nodes_as_compound_command(
106108
107109
108110def evaluate_nodes_as_simple_command (
109- nodes : list [bashlex .ast .node ], context : NodeExecutionContext
111+ nodes : Iterable [bashlex .ast .node ], context : NodeExecutionContext
110112) -> str :
111113 command = [evaluate_node (part , context = context ) for part in nodes ]
112114 return context .executor (command , context .environment )
0 commit comments