Last modified: 2014-08-04 16:02:00 UTC
In compat, templatesWithParams from class Page used to provide a pair containing the template name and a list of parameters, with the full "key=value" string. Nowadays, we're getting a dictionary instead of that list. Normally there is nothing wrong with that, except that in Python 2 the dictionary is unordered, which means that: * the order of the parameters is forever lost - this can be easily solved using OrderedDict instead. * the original text cannot be reconstructed (because of the above and the missing whitespace information) - this means there is no easy way to identify and/or replace a particular instance of the template in a page with many identical templates.
(In reply to Strainu from comment #0) > * the original text cannot be reconstructed (because of the above and > the missing whitespace information) - this means there is no easy way > to identify and/or replace a particular instance of the template in a > page with many identical templates. If you're looking for a way to preserve spacing rules, try mwparserfromhell: http://mwparserfromhell.readthedocs.org
Change 126147 had a related patch set uploaded by Ricordisamoa: use collections.OrderedDict instead of built-in dict for params https://gerrit.wikimedia.org/r/126147
Change 126147 merged by jenkins-bot: use collections.OrderedDict instead of built-in dict for params https://gerrit.wikimedia.org/r/126147
Reverted in https://gerrit.wikimedia.org/r/#/c/127467/ because orderedDict is not availlable in python < 2.7
We could use https://pypi.python.org/pypi/ordereddict
What about just: try: from collections import OrderedDict except ImportError OrderedDict = dict
(In reply to Kunal Mehta (Legoktm) from comment #6) Preserving the order when OrderedDict is available while discarding it otherwise would be an inconsistent behavior.
(In reply to Ricordisamoa from comment #7) > > Preserving the order when OrderedDict is available while discarding it > otherwise would be an inconsistent behavior. I suppose. I think bundling the ordereddict pypi package is a good idea then.
The python layer for ItemPage.claims is greatly simpified if it is an ordered set. The qualifiers also have an order that needs to be preserved by default and manipulatable.
Change 140212 had a related patch set uploaded by Merlijn van Deen: use collections.OrderedDict instead of built-in dict for params https://gerrit.wikimedia.org/r/140212
Are there some complicated structures that we should add to the unit tests to ensure it correctly organises them?