#20287: BaseContext (and it's subclasses) lack emulation of dictionary items() -------------------------------------+------------------------------------- Reporter: Keryn Knight | Owner: nobody <django@…> | Status: new Type: New feature | Version: master Component: Template system | Resolution: Severity: Normal | Triage Stage: Accepted Keywords: | Needs documentation: 0 Has patch: 0 | Patch needs improvement: 0 Needs tests: 0 | UI/UX: 0 Easy pickings: 0 | -------------------------------------+-------------------------------------
Comment (by cannona): I'm a bit confused on what __iterkeys__ and the like should output. My first guess would be that it should iterate through the union of all the keys of the dictionaries in the stack of dicts, (I.E. no duplicate keys). __itervalues__ should return the same value as calling __getitem__ would for that particular key. However, this does not seem to jive with what __itter__ is yielding, which is each dictionary in the stack of dicts. Does it make sense to have __iter__ return one thing, while __itervalues__ and __iterkeys__ returns something entirely different? My suggestion would be to add all the various basic map methods to iterate over the keys and values as I described at the beginning of this comment, , and changing __iter__ to match, I.E. it would yield each key and value pair from the stack, where items in later dictionaries in the stack override the earlier ones, and all keys would be returned only once. I'm just not sure if this would be likely to screw up existing code. Implementing __iterkeys__ and __itervalues__ and other methods in RenderContext will be quite simple, as they can just proxy to self.dicts[-1].__methodname__. In fact, the get method that's already in there should probably do that as well, rather than rewriting logic already provided. Please let me know if any of the above is not clear. Aaron -- Ticket URL: <https://code.djangoproject.com/ticket/20287#comment:5> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.