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
PEP 372: OrderedDict #49647
Comments
Here is a working patch implementing PEP-372 ordered dictionaries. |
Doc nits:
Implementation nits:
|
In SubclassMappingTests, MyOrderedDict should subclass OrderedDict |
|
Thanks for the review comments guys. An updated patch is attached. |
I still see an "OrderDict" in the docs, and the TypeError in __init__ |
Fixed. |
Added a few more tests. |
I would try to make it more explicit that updates do not reset the Maybe change: """ to [removed "first", added longer explanation] """ |
I would also recommend strengthening some of the tests with regard to TestOrderedDict.test_update does verify that updated items are not test_iterators, test_popitem, and test_pop check only single test_setdefault should also verify that x is the final key, and that I didn't see any tests for insert a, insert b, delete a, re-insert a, |
Jim, I updated the docs to talk cover delete-reinsert. Also, added a few more tests as suggested but am leaving test_iterators, |
At Antoine's request, strengthened the tests in test_copying. |
Attaching update reflecting Guido's change to __eq__(). |
Checked-in r70101 and r70102 |
Maybe premature optimization but maybe it would make sense to implement def __eq__(self, other):
if isinstance(other, OrderedDict):
if not dict.__eq__(self, other):
return False
return all(p == q for p, q in _zip_longest(self.items(),
other.items()))
return dict.__eq__(self, other) For the most likely case (that dicts are different) this should give a |
I was just reading the PEP, and caught this bit: "Does OrderedDict.popitem() return a particular key/value pair? Okay, but I'd also like a convenient and fast way to find the oldest |
I wonder if, instead of all kinds of new APIs, the _keys list could just Of course, that makes further optimization or a rewrite in C harder. |
The internal data structure *must* remain private so that we can build a |
Forest, for your use case I recommend copying the code to a new class |
Thinking it through a bit more, and LRU cache would actually need to |
Even then the keys list could be offered as a property. |
Forest, I've taken another look at what's involved and am inclined to |
Please no. We just decided to *not* extend the API. The PEP originally I don't think implementing an LRUCache on an ordered dict is a good |
OK, disregard my suggestions, it's better not to have a property that |
Agreed here. Thanks, gents. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: