Worarrounding hardcoded Option class in optparse in Python 2.3

Pupeno pupeno at pupeno.com
Thu Jul 27 04:46:40 EDT 2006


For the record, the copy and paste fix seems to have worked, so far.

Pupeno wrote:

> Hello,
> I am doing some extreme use of optparse, that is, extending it as
> explained on
> http://docs.python.org/lib/optparse-other-reasons-to-extend-optparse.html
> I have subclassed OptionParser and Option. MyOptionParser uses MyOption as
> option_class and in Python 2.4 it works. But I have to target Python 2.3.
> In Python 2.3 the help and version options seem to be created before even
> a parser is created and they are created using a hardcoded call to Option.
> So, they are not using MyOption. I am creating MyOption specifically for
> the help and version Option so I need the to be MyOption.
> I check out the documentation of this module for Python 2.3 and it
> recommends the same procedure:
> http://www.python.org/doc/2.3/lib/optparse-extending-other-reasons.html
> Is this a bug in Python 2.3 that was solved in 2.4 and nobody cared to
> backport ?
> At any rate, what are my options (no pun intended) ?
> I could copy and paste the fix[1] from Python 2.4 into MyOptionParser; I
> checked it carefull and it seems it would work, but I am not sure, does
> anybody know ?
> Should I override the hardcoded module variables of optparse in 2.3 ?
> (that seems like a bad, bad idea).
> I am open to suggestions.
> Thanks.

-- 
Pupeno <pupeno at pupeno.com> (http://pupeno.com)



More information about the Python-list mailing list