-
Notifications
You must be signed in to change notification settings - Fork 192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make InlineTableDict inherit from OrderedDict #86
Conversation
Also included in this patch is the removal of the specialized |
Hi Ryan, Thanks for the patch. I am leaning towards accepting it but I would like to get @nateprewitt's thoughts on it since he has an actual use case for the feature that this affects (per #74). -Will |
Thanks for taking the time to pull me in @uiri. I meant to respond to your original comments @ryanhiebert but that somehow slipped off the checklist. So I completely agree with the removal of the As for using an OrderedDict for _InlineTableDict, this current implementation doesn't work with Python 2.6. We're maintaining support for 2.6 for the immediate future in This is also adding functionality, which is probably fine, but will change how this library has operated for most of its existence. I'm not entirely convinced that I think if That's just my 2 cents though, feel free to do what you feel is best for the library and we'll cope. Thanks for your work @uiri and @ryanhiebert! |
I certainly don't want that. What would you think about adding a dependency on ordereddict for Python 2.6? If I were the one to have designed this library (though it's likely a good thing I wasn't) I would have just done OrderedDict everywhere. Because we expect TOML files to be edited by humans, it's a fact of life that the order of the keys does matter, at least to the human. We can dictate that it doesn't matter, and can force it on computers, but humans do care when their files change in useless ways. If you think adding the dependency is unwise, then I'd be inclined to pursue creating a dynamic subclass using One possible wrench in that idea is whether we see |
I want to maintain as much backwards compatibility as is reasonable. I have modified the .travis.yml file to that end. Ryan, I rebased your PR commit as 48657a9 and, predictably, it fails on Python 2.6
I would rather avoid that if possible. Currently, the library has no dependencies outside of the Python standard library and I would prefer to keep it that way. Using Thank you Ryan for pointing out the issues with the existing |
I'll work under the assumption that you already know it, but to be sure, I want to clarify that the dependency would only affect Python 2.6. It would not be installed for any other version. What I'm thinking, then, is that I'll pull out the uncontroversial fixup for |
Just to note, I already made the changes relating to dynamic subclassing that you have suggested (in a separate branch).
My comments below reflect my understanding of what you mean by "the power of I'm not really sure that I do think that downstream users of the library may wish to know whether or not a given dictionary is an inline table, but that exposing that in the form of internal implementation details (in this case, a sentinel class) is less than ideal. I'm not sure what the best way to expose it is. I would prefer to take a more functional approach but I'm also concerned about extensibility beyond simply exposing information about inline tables. #77 comes to mind as something which would be better handled on an as-needed basis by a user of the library. The API exposed by the library right now is rather simple and functional (in the sense of not particularly object oriented): To take a cue from Python's |
The approach that I saw in that branch looks good to me. I'd recommend leaving In functional programming you'll tend to really good uses of data types. I think that If this is not a public interface, then consumers of this library are not able to write a new toml file, without reading an old one, and have it use any inline tables. I think that there should be a way for users that don't need I like the functional approach, so the Encoder/Decoder classes don't jive well with my own thoughts. However, I've not used the json equivalents except in the most trivial of ways (just copy-pasting, basically), so I may not be a good judge of whether they are indeed the better approach. I think at this point this particular PR is dead, and your work on that other branch should be how we implement what this desires, so I'm gonna go ahead and close it. |
Oh, and even if you decide that you have valid case for not inheriting from dict, make sure it at least inherits from object, to ensure we're using a new-style class there in Python 2. |
References my review comment from #75.
I first looked at creating an analog to
_dict
, that I was thinking to call_InlineTableDict
. However, while I was doing that it became apparent that it would end up as a pretty infectious change, which would require change to at around 4 method signatures and 8 call sites._dict
is only a parameter forload
andloads
, so that just didn't seem like the best approach.My thinking with this pull request is that there is a complexity trade-off from choosing to make
InlineTableDict
overridable, and that's it's not worth what it costs.OrderedDict
has good performance characteristics, and Python 3.6 has even made the default dict order-preserving. Combined with the relatively limited use we'd expect to see withInlineTableDict
over our standard use ofdict
, it seemed to me to be a reasonable choice.If you disagree with my assessment, I'm willing to open another pull request with the required changes to add an
_InlineTableDict
parameter toload
andloads
for comparison.