-
Notifications
You must be signed in to change notification settings - Fork 181
If using Python >=3.7, use built-in dict as OrderedDict #248
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
If using Python >=3.7, use built-in dict as OrderedDict #248
Conversation
Since dictionaries are specified to preserve insertion order in Python 3.7 and up (see https://docs.python.org/3/whatsnew/3.7.html), it seems simplest and most performant to use the built-in type where possible.
I've tried a couple of different ways to write this in a way that |
Why don't you simply set |
@Cito it looks like that's a slightly bigger change, because it changes the way that I was going to look into the details of the GraphQL specification this weekend to see if that's necessary, and propose we remove that test if it's not required -- if you know already, I'd love to simplify this. |
@necaris - you mean The question is - what is the desired behavior?
Depending on which behavior is actually desired, we need to change the test or the implementation of Personally I think solution 2 makes more sense. In that case we would need to simply skip the test for Py >= 3.7 since no "unordered" dict exists in that case. (Btw, actually dicts are already ordered in Py 3.6, but it's only guaranteed in CPython.) |
@Cito yes, that's exactly the test I mean. I agree with you that solution 2 works well, and I've updated my PR to reflect that and skip the test. However, it's still not clear what the behavior should be -- I'm sure the sorting was done for a reason, even though as far as I can see, the GraphQL spec doesn't require it at all. |
The reason for the sorting was probably to achieve a deterministic behavior which makes testing easier. GraphQL.js uses a Map internally which is ordered. Note that in graphql-core-next, the "values" attribute is a dict and only Py 3.6+ anyway, so the problem does not arise there. |
@Cito sure, that could be a reason. If using a built-in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
Since dictionaries are specified to preserve insertion order in Python 3.7 and up (see https://docs.python.org/3/whatsnew/3.7.html), it seems simplest and most performant to use the built-in type where possible.
This change does specify a distinct type, to continue to make clear that in certain situations order-preservation is relied on rather than being a convenient accident.