You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
0.15.3: str-based Enum values are written as "Color.RED" instead of their value #725
Since 0.15.3, a value that is a str subclass with its own __str__, such as a (str, Enum) member, is written using __str__ instead of its string value. 0.15.2 wrote the value.
If __str__ returns text with a quote, the output is not valid TOML. For example, with def __str__(self): return 'shown "x' the output is k = "shown "x", and tomlkit.parse rejects it.
It starts at 73078ea ("Speed up escaping strings and keys when writing TOML", #709). When no character needs escaping, escape_string in tomlkit/_utils.py now returns str(s). For a str subclass that calls the subclass's __str__. Before #709 the result was built from the characters of s, so it was always the underlying string. return str.__str__(s) keeps the speed-up and returns the underlying text; with that one-line change on master (3cdcbde) the example prints color = "red" and the test suite passes (803 passed, 1 skipped, tests/test_toml_tests.py excluded because its data files are not in the checkout).
Found while testing code-review tools on recent tomlkit commits; reproduced with the PyPI wheels above.
Activity