|
7 | 7 | from psij.utils import path_object_to_full_path as o2p |
8 | 8 |
|
9 | 9 |
|
| 10 | +class _EnvDict(dict): |
| 11 | + |
| 12 | + def __init__(self, *args, **kwargs): |
| 13 | + |
| 14 | + super().__init__(*args, **kwargs) |
| 15 | + |
| 16 | + def __setitem__(self, k, v): |
| 17 | + |
| 18 | + if not isinstance(k, str): |
| 19 | + raise TypeError('environment key "%s" is not a string (%s)' |
| 20 | + % (k, type(k).__name__)) |
| 21 | + if not isinstance(v, str): |
| 22 | + raise TypeError('environment key "%s" has non-string value (%s)' |
| 23 | + % (k, type(v).__name__)) |
| 24 | + super().__setitem__(k, v) |
| 25 | + |
| 26 | + |
10 | 27 | class JobSpec(object): |
11 | 28 | """A class to hold information about the characteristics of a:class:`~psij.Job`.""" |
12 | 29 |
|
@@ -116,15 +133,12 @@ def environment(self) -> Optional[Dict[str, str]]: |
116 | 133 |
|
117 | 134 | @environment.setter |
118 | 135 | def environment(self, environment: Optional[Dict[str, str]]) -> None: |
119 | | - if environment is not None: |
| 136 | + if environment is None: |
| 137 | + self._environment = None |
| 138 | + else: |
| 139 | + self._environment = _EnvDict() |
120 | 140 | for k, v in environment.items(): |
121 | | - if not isinstance(k, str): |
122 | | - raise TypeError('environment key "%s" is not a string (%s)' |
123 | | - % (k, type(k).__name__)) |
124 | | - if not isinstance(v, str): |
125 | | - raise TypeError('environment key "%s" has non-string value (%s)' |
126 | | - % (k, type(v).__name__)) |
127 | | - self._environment = environment |
| 141 | + self._environment[k] = v |
128 | 142 |
|
129 | 143 | @property |
130 | 144 | def to_dict(self) -> Dict[str, Any]: |
|
0 commit comments