1
1
from __future__ import annotations
2
2
3
3
import subprocess
4
- from collections .abc import Sequence
4
+ from collections .abc import Iterable , Mapping , Sequence
5
5
from dataclasses import dataclass
6
6
from typing import Callable , Dict , List # noqa: TID251
7
7
11
11
EnvironmentExecutor = Callable [[List [str ], Dict [str , str ]], str ]
12
12
13
13
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 :
15
15
return subprocess .run (command , env = env , text = True , stdout = subprocess .PIPE , check = True ).stdout
16
16
17
17
@@ -23,7 +23,7 @@ class NodeExecutionContext:
23
23
24
24
25
25
def evaluate (
26
- value : str , environment : dict [str , str ], executor : EnvironmentExecutor | None = None
26
+ value : str , environment : Mapping [str , str ], executor : EnvironmentExecutor | None = None
27
27
) -> str :
28
28
if not value :
29
29
# empty string evaluates to empty string
@@ -41,7 +41,9 @@ def evaluate(
41
41
return evaluate_node (
42
42
value_word_node ,
43
43
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 ,
45
47
),
46
48
)
47
49
@@ -106,7 +108,7 @@ def evaluate_nodes_as_compound_command(
106
108
107
109
108
110
def evaluate_nodes_as_simple_command (
109
- nodes : list [bashlex .ast .node ], context : NodeExecutionContext
111
+ nodes : Iterable [bashlex .ast .node ], context : NodeExecutionContext
110
112
) -> str :
111
113
command = [evaluate_node (part , context = context ) for part in nodes ]
112
114
return context .executor (command , context .environment )
0 commit comments