Closed abrahammurciano closed 1 year ago
If I have a custom class that's a subtype of say str, I'd expect it to be dumped the same way as a string. For example:
str
from enum import StrEnum import toml class ValidStrings(StrEnum): FOO = "foo" data = {"foo": ValidStrings.FOO} print(toml.dumps(data))
Output:
foo = [ "f", "o", "o",]
I've done some investigating and it seems to be because in TomlEncoder.dump_value it tries to determine the dump function like this:
TomlEncoder.dump_value
dump_fn = self.dump_funcs.get(type(v))
Perhaps isinstance should be used instead to play nice with inheritence? I'd suggest this:
dump_fn = next(f for t, f in self.dump_funcs.items() if isinstance(v, t), None)
I'd be happy to open a pull request for this
This is awfully embarrassing... I seem to have opened this issue in the wrong repository... This was meant for toml
toml
If I have a custom class that's a subtype of say
str
, I'd expect it to be dumped the same way as a string. For example:Output:
I've done some investigating and it seems to be because in
TomlEncoder.dump_value
it tries to determine the dump function like this:Perhaps isinstance should be used instead to play nice with inheritence? I'd suggest this:
I'd be happy to open a pull request for this