|
17 | 17 | from ruamel.yaml.comments import CommentedMap, CommentedSeq, Format
|
18 | 18 | from ruamel.yaml.composer import ComposerError
|
19 | 19 | from ruamel.yaml.constructor import RoundTripConstructor
|
| 20 | +from ruamel.yaml.docinfo import Version |
20 | 21 | from ruamel.yaml.emitter import Emitter, ScalarAnalysis
|
21 | 22 |
|
22 | 23 | # Module 'ruamel.yaml' does not explicitly export attribute 'YAML'; implicit reexport disabled
|
@@ -1028,15 +1029,23 @@ def version(self) -> tuple[int, int] | None:
|
1028 | 1029 | return None
|
1029 | 1030 |
|
1030 | 1031 | @version.setter
|
1031 |
| - def version(self, val: tuple[int, int] | None) -> None: |
| 1032 | + def version(self, val: str | tuple[int, int] | list[int] | Version | None) -> None: |
1032 | 1033 | """Ensure that yaml version uses our default value.
|
1033 | 1034 |
|
1034 | 1035 | The yaml Reader updates this value based on the ``%YAML`` directive in files.
|
1035 | 1036 | So, if a file does not include the directive, it sets this to None.
|
1036 | 1037 | But, None effectively resets the parsing version to YAML 1.2 (ruamel's default).
|
1037 | 1038 | """
|
1038 | 1039 | if val is not None:
|
1039 |
| - self._yaml_version = val |
| 1040 | + if isinstance(val, tuple): |
| 1041 | + self._yaml_version = val |
| 1042 | + elif isinstance(val, list): |
| 1043 | + self._yaml_version = (val[0], val[1]) |
| 1044 | + elif isinstance(val, Version): |
| 1045 | + self._yaml_version = (val.major, val.minor) |
| 1046 | + else: |
| 1047 | + msg = f"Unsupported argument {val}" |
| 1048 | + raise TypeError(msg) |
1040 | 1049 | elif hasattr(self, "_yaml_version_default"):
|
1041 | 1050 | self._yaml_version = self._yaml_version_default
|
1042 | 1051 | # We do nothing if the object did not have a previous default version defined
|
|
0 commit comments