Takes a list of set specification in standard form (option=value). Options that are known are updated immediately. If defer is true, options that are not known are deferred, and will be set once they are added. May raise an `OptionsError` if a value is malfo
(self, *specs: str, defer: bool = False)
| 308 | ) |
| 309 | |
| 310 | def set(self, *specs: str, defer: bool = False) -> None: |
| 311 | """ |
| 312 | Takes a list of set specification in standard form (option=value). |
| 313 | Options that are known are updated immediately. If defer is true, |
| 314 | options that are not known are deferred, and will be set once they |
| 315 | are added. |
| 316 | |
| 317 | May raise an `OptionsError` if a value is malformed or an option is unknown and defer is False. |
| 318 | """ |
| 319 | # First, group specs by option name. |
| 320 | unprocessed: dict[str, list[str]] = {} |
| 321 | for spec in specs: |
| 322 | if "=" in spec: |
| 323 | name, value = spec.split("=", maxsplit=1) |
| 324 | unprocessed.setdefault(name, []).append(value) |
| 325 | else: |
| 326 | unprocessed.setdefault(spec, []) |
| 327 | |
| 328 | # Second, convert values to the correct type. |
| 329 | processed: dict[str, Any] = {} |
| 330 | for name in list(unprocessed.keys()): |
| 331 | if name in self._options: |
| 332 | processed[name] = self._parse_setval( |
| 333 | self._options[name], unprocessed.pop(name) |
| 334 | ) |
| 335 | |
| 336 | # Third, stash away unrecognized options or complain about them. |
| 337 | if defer: |
| 338 | self.deferred.update( |
| 339 | {k: _UnconvertedStrings(v) for k, v in unprocessed.items()} |
| 340 | ) |
| 341 | elif unprocessed: |
| 342 | raise exceptions.OptionsError( |
| 343 | f"Unknown option(s): {', '.join(unprocessed)}" |
| 344 | ) |
| 345 | |
| 346 | # Finally, apply updated options. |
| 347 | self.update(**processed) |
| 348 | |
| 349 | def process_deferred(self) -> None: |
| 350 | """ |
nothing calls this directly
no test coverage detected