Fix `toml` encoding circular reference error. #110

This commit is contained in:
Fabio Caccamo 2022-09-06 13:11:15 +02:00
parent 6761f54e45
commit 195ed03ae1
2 changed files with 28 additions and 1 deletions

View File

@ -18,5 +18,5 @@ class TOMLSerializer(AbstractSerializer):
return data
def encode(self, d, **kwargs):
data = toml.dumps(d, **kwargs)
data = toml.dumps(dict(d), **kwargs)
return data

View File

@ -0,0 +1,27 @@
# -*- coding: utf-8 -*-
from benedict import benedict
# import toml
import unittest
class github_issue_0110_test_case(unittest.TestCase):
"""
This class describes a github issue 0110 test case.
https://github.com/fabiocaccamo/python-benedict/issues/110
To run this specific test:
- Run python -m unittest tests.github.test_issue_0110
"""
def test_toml_circular_reference_detected(self):
d = {"a": {"b": {"c": 1}}}
d["e"] = benedict({"f": 2})
b = benedict()
b.update(d)
# b.merge(d)
t = b.to_toml()
print(t)