Last modified: 2014-08-04 16:02:00 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T57882, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 55882 - The order of parameters is lost when using extract_templates_and_params() and extract_templates_and_params_regex()
The order of parameters is lost when using extract_templates_and_params() and...
Status: PATCH_TO_REVIEW
Product: Pywikibot
Classification: Unclassified
textlib.py (Other open bugs)
core-(2.0)
All All
: Normal normal
: ---
Assigned To: Pywikipedia bugs
:
Depends on:
Blocks: 55880
  Show dependency treegraph
 
Reported: 2013-10-18 16:38 UTC by Strainu
Modified: 2014-08-04 16:02 UTC (History)
5 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments

Description Strainu 2013-10-18 16:38:30 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.
Comment 1 Ricordisamoa 2014-04-15 21:58:12 UTC
(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
Comment 2 Gerrit Notification Bot 2014-04-15 22:18:22 UTC
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
Comment 3 Gerrit Notification Bot 2014-04-20 11:05:43 UTC
Change 126147 merged by jenkins-bot:
use collections.OrderedDict instead of built-in dict for params

https://gerrit.wikimedia.org/r/126147
Comment 4 xqt 2014-04-20 16:19:13 UTC
Reverted in https://gerrit.wikimedia.org/r/#/c/127467/ because orderedDict is not availlable in python < 2.7
Comment 5 Ricordisamoa 2014-04-23 22:51:52 UTC
We could use https://pypi.python.org/pypi/ordereddict
Comment 6 Kunal Mehta (Legoktm) 2014-05-04 06:47:49 UTC
What about just:

try:
    from collections import OrderedDict
except ImportError
    OrderedDict = dict
Comment 7 Ricordisamoa 2014-05-04 07:05:31 UTC
(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.
Comment 8 Kunal Mehta (Legoktm) 2014-05-10 09:14:11 UTC
(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.
Comment 9 John Mark Vandenberg 2014-06-01 00:56:29 UTC
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.
Comment 10 Gerrit Notification Bot 2014-06-17 20:29:23 UTC
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
Comment 11 John Mark Vandenberg 2014-08-04 16:02:00 UTC
Are there some complicated structures that we should add to the unit tests to ensure it correctly organises them?

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links