@@ -21,6 +21,18 @@ def _to_path(arg: Union[str, pathlib.Path, None]) -> Optional[pathlib.Path]:
2121 return pathlib .Path (arg )
2222
2323
24+ def _to_env_dict (arg : Union [Dict [str , Union [str , int ]], None ]) -> Dict [str , str ]:
25+ if arg is None :
26+ return dict ()
27+ ret = dict ()
28+ for k ,v in arg .items ():
29+ if isinstance (v , int ):
30+ ret [k ] = str (v )
31+ else :
32+ ret [k ] = v
33+ return ret
34+
35+
2436class JobSpec (object ):
2537 """A class that describes the details of a job."""
2638
@@ -125,7 +137,7 @@ def __init__(self, executable: Optional[str] = None, arguments: Optional[List[st
125137 # care of the conversion, but mypy gets confused
126138 self ._directory = _to_path (directory )
127139 self .inherit_environment = inherit_environment
128- self .environment = environment
140+ self .environment = _to_env_dict ( environment )
129141 self ._stdin_path = _to_path (stdin_path )
130142 self ._stdout_path = _to_path (stdout_path )
131143 self ._stderr_path = _to_path (stderr_path )
@@ -160,15 +172,7 @@ def environment(self) -> Optional[Dict[str, str]]:
160172 @environment .setter
161173 def environment (self , env : Optional [Dict [str , Union [str , int ]]]) -> None :
162174 """Ensure env dict values to be string typed."""
163- self ._environment = None
164-
165- if env :
166- self ._environment = {}
167- for k , v in env .items ():
168- if isinstance (v , int ):
169- self ._environment [k ] = str (v )
170- else :
171- self ._environment [k ] = v
175+ self ._environment = _to_env_dict (env )
172176
173177 @property
174178 def directory (self ) -> Optional [pathlib .Path ]:
0 commit comments