diff --git a/lib/yaml/representer.py b/lib/yaml/representer.py index 808ca06df..9dd4e8f70 100644 --- a/lib/yaml/representer.py +++ b/lib/yaml/representer.py @@ -233,7 +233,7 @@ def represent_undefined(self, data): SafeRepresenter.add_representer(type(None), SafeRepresenter.represent_none) -SafeRepresenter.add_representer(str, +SafeRepresenter.add_multi_representer(str, SafeRepresenter.represent_str) SafeRepresenter.add_representer(bytes, diff --git a/tests/test_dump_load.py b/tests/test_dump_load.py index 8c4352bd1..caa24dd89 100644 --- a/tests/test_dump_load.py +++ b/tests/test_dump_load.py @@ -1,3 +1,6 @@ +import enum +import sys + import pytest import yaml @@ -13,3 +16,11 @@ def test_load_no_loader(): def test_load_safeloader(): assert yaml.load("- foo\n", Loader=yaml.SafeLoader) + + +@pytest.mark.skipif(sys.version_info < (3, 11), reason="StrEnum was added in Python 3.11") +def test_StrEnum(): + class TestEnum(enum.StrEnum): + TEST_VALUE = "test value" + + assert yaml.load(yaml.dump(TestEnum.TEST_VALUE), Loader=yaml.SafeLoader) == TestEnum.TEST_VALUE