https://bugzilla.wikimedia.org/show_bug.cgi?id=55882
Web browser: --- Bug ID: 55882 Summary: The order of parameters is lost when using templatesWithParams Product: Pywikibot Version: core (2.0) Hardware: All OS: All Status: NEW Severity: normal Priority: Unprioritized Component: General Assignee: Pywikipedia-bugs@lists.wikimedia.org Reporter: crangasi2001@yahoo.com Blocks: 55880 Classification: Unclassified Mobile Platform: ---
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.
https://bugzilla.wikimedia.org/show_bug.cgi?id=55882
Amir Ladsgroup ladsgroup@gmail.com changed:
What |Removed |Added ---------------------------------------------------------------------------- Priority|Unprioritized |Normal CC| |ladsgroup@gmail.com
https://bugzilla.wikimedia.org/show_bug.cgi?id=55882
--- Comment #1 from Ricordisamoa ricordisamoa@live.it --- (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
https://bugzilla.wikimedia.org/show_bug.cgi?id=55882
--- Comment #2 from Gerrit Notification Bot gerritadmin@wikimedia.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
https://bugzilla.wikimedia.org/show_bug.cgi?id=55882
Gerrit Notification Bot gerritadmin@wikimedia.org changed:
What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |PATCH_TO_REVIEW
https://bugzilla.wikimedia.org/show_bug.cgi?id=55882
Ricordisamoa ricordisamoa@live.it changed:
What |Removed |Added ---------------------------------------------------------------------------- Assignee|Pywikipedia-bugs@lists.wiki |ricordisamoa@live.it |media.org |
https://bugzilla.wikimedia.org/show_bug.cgi?id=55882
Ricordisamoa ricordisamoa@live.it changed:
What |Removed |Added ---------------------------------------------------------------------------- Assignee|ricordisamoa@live.it |Pywikipedia-bugs@lists.wiki | |media.org
--- Comment #5 from Ricordisamoa ricordisamoa@live.it --- We could use https://pypi.python.org/pypi/ordereddict
https://bugzilla.wikimedia.org/show_bug.cgi?id=55882
Kunal Mehta (Legoktm) legoktm.wikipedia@gmail.com changed:
What |Removed |Added ---------------------------------------------------------------------------- CC| |legoktm.wikipedia@gmail.com
--- Comment #6 from Kunal Mehta (Legoktm) legoktm.wikipedia@gmail.com --- What about just:
try: from collections import OrderedDict except ImportError OrderedDict = dict
https://bugzilla.wikimedia.org/show_bug.cgi?id=55882
--- Comment #7 from Ricordisamoa ricordisamoa@live.it --- (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.
https://bugzilla.wikimedia.org/show_bug.cgi?id=55882
--- Comment #8 from Kunal Mehta (Legoktm) legoktm.wikipedia@gmail.com --- (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.
https://bugzilla.wikimedia.org/show_bug.cgi?id=55882
John Mark Vandenberg jayvdb@gmail.com changed:
What |Removed |Added ---------------------------------------------------------------------------- CC| |jayvdb@gmail.com
--- Comment #9 from John Mark Vandenberg jayvdb@gmail.com --- 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.
https://bugzilla.wikimedia.org/show_bug.cgi?id=55882
--- Comment #10 from Gerrit Notification Bot gerritadmin@wikimedia.org --- 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
https://bugzilla.wikimedia.org/show_bug.cgi?id=55882
Gerrit Notification Bot gerritadmin@wikimedia.org changed:
What |Removed |Added ---------------------------------------------------------------------------- Status|REOPENED |PATCH_TO_REVIEW
https://bugzilla.wikimedia.org/show_bug.cgi?id=55882
Ricordisamoa ricordisamoa@openmailbox.org changed:
What |Removed |Added ---------------------------------------------------------------------------- Component|General |textlib.py Summary|The order of parameters is |The order of parameters is |lost when using |lost when using |templatesWithParams |extract_templates_and_param | |s() and | |extract_templates_and_param | |s_regex()
https://bugzilla.wikimedia.org/show_bug.cgi?id=55882
--- Comment #11 from John Mark Vandenberg jayvdb@gmail.com --- Are there some complicated structures that we should add to the unit tests to ensure it correctly organises them?
pywikipedia-bugs@lists.wikimedia.org