From 4d6130b8e7c9daadcc1d5848a01055b45fd23a4e Mon Sep 17 00:00:00 2001 From: "Bernhard W. Radermacher" <31952794+bradermacher@users.noreply.github.com> Date: Thu, 5 Nov 2020 10:25:02 +0100 Subject: [PATCH] issue 285 in dump_inline_table change the isinstance check to look for collections.abc.Mapping, not for dict. This enables UserDict and other classes that derive from collections.abc.Mapping, in addition to dict. additional change - missed two checks. --- toml/encoder.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/toml/encoder.py b/toml/encoder.py index bf17a72..e5f81aa 100644 --- a/toml/encoder.py +++ b/toml/encoder.py @@ -1,3 +1,4 @@ +import collections import datetime import re import sys @@ -161,7 +162,7 @@ def dump_inline_table(self, section): https://github.com/toml-lang/toml#user-content-inline-table """ retval = "" - if isinstance(section, dict): + if isinstance(section, collections.abc.Mapping): val_list = [] for k, v in section.items(): val = self.dump_inline_table(v) @@ -190,11 +191,11 @@ def dump_sections(self, o, sup): qsection = section if not re.match(r'^[A-Za-z0-9_-]+$', section): qsection = _dump_str(section) - if not isinstance(o[section], dict): + if not isinstance(o[section], collections.abc.Mapping): arrayoftables = False if isinstance(o[section], list): for a in o[section]: - if isinstance(a, dict): + if isinstance(a, collections.abc.Mapping): arrayoftables = True if arrayoftables: for a in o[section]: