Page MenuHomePhabricator

editarticle uses deprecated optparser
Closed, ResolvedPublic

Description

optparser was deprecated in py 2.7
https://docs.python.org/2/library/argparse.html#module-argparse

It is used by editarticle.py


Version: core-(2.0)
Severity: trivial

Event Timeline

bzimport raised the priority of this task from to Low.Nov 22 2014, 3:37 AM
bzimport set Reference to bz68617.
bzimport added a subscriber: Unknown Object (????).

"Deprecated since version 3.2: The optparse module is deprecated and will not be developed further; development will continue with the argparse module."

https://docs.python.org/3/library/optparse.html

Would that be a task suitable for Google Code-in and would somebody be willing to mentor a student? If so, feel free to add to https://www.mediawiki.org/wiki/Google_Code-in_2014#Proposed_tasks

That was my intention with marking it as easy. Added it to the proposed tasks.

The GCI task reads

The Pywikibot script named "editarticle.py" uses optparse which is deprecated in Python 3.2, this should be replaced by argparse

Should that not be "replaced by handleArgs"?

No not really: handleArgs (or how it's now called handle_args) is already called (in line 46), but this request is about parsing the script specific parameters. And there are several ways to do that. Currently most scripts are doing it manually by iterating through the entries and then “doing it's stuff” but this is using optparse.

Now depending on how fast the argparse patch (https://gerrit.wikimedia.org/r/156089/) is going to be imported it would be better to just change the optparse into argparse. That is relatively easy and with that linked patch the adjustments are minimal.

Change 176747 had a related patch set uploaded (by Mloc-gci):
editarticle: move from optparse to argparse

https://gerrit.wikimedia.org/r/176747

Patch-For-Review

Change 176747 merged by jenkins-bot:
editarticle: move from optparse to argparse

https://gerrit.wikimedia.org/r/176747

jayvdb claimed this task.

The build with this change merged was successful.

https://travis-ci.org/wikimedia/pywikibot-core/builds/42813041

This script could now be used as an example implementation for T76429.

jayvdb set Security to None.
jayvdb removed a subscriber: Unknown Object (????).