From 6e05a3e0d27182b21381455751fcff0ec57f7d53 Mon Sep 17 00:00:00 2001 From: Jacob Hayes Date: Tue, 10 Jul 2018 20:58:57 -0500 Subject: [PATCH] [#2504] Serialize prettytoml ArrayElements as lists --- pipenv/project.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pipenv/project.py b/pipenv/project.py index 7f40576d..d0d21c3e 100644 --- a/pipenv/project.py +++ b/pipenv/project.py @@ -14,6 +14,7 @@ import pipfile.api import six import toml import json as simplejson +from prettytoml.elements.array import ArrayElement from ._compat import Path @@ -64,6 +65,12 @@ def _normalized(p): DEFAULT_NEWLINES = u"\n" +def encode_toml_elements(obj): + if isinstance(obj, ArrayElement): + return obj.primitive_value + raise TypeError(repr(obj) + " is not JSON serializable") + + def preferred_newlines(f): if isinstance(f.newlines, six.text_type): return f.newlines @@ -631,7 +638,8 @@ class Project(object): """ newlines = self._lockfile_newlines s = simplejson.dumps( # Send Unicode in to guarentee Unicode out. - content, indent=4, separators=(u",", u": "), sort_keys=True + content, indent=4, separators=(u",", u": "), sort_keys=True, + default=encode_toml_elements, ) with atomic_open_for_write(self.lockfile_location, newline=newlines) as f: f.write(s)