Opened 4 years ago

Closed 4 years ago

#4858 defect closed fixed (fixed)

twisted.python.usage.Options errors when generic code for usage.Options definition has multiple underscores.

Reported by: t_venkatesh Owned by:
Priority: normal Milestone:
Component: core Keywords:
Cc: Branch: branches/underscore-options-4858
(diff, github, buildbot, log)
Author: t_venkatesh, exarkun Launchpad Bug:

Description

When the generic code for options method has multiple underscores, and a short name is declared, twisted produces a traceback.

To reproduce define:

from twisted.python import usage
class TestOptions(usage.Options):
    def opt_verbose_big(self):
        "Call this multiple times to increment verbosity"
        self['verbosity'] += 1
    opt_v = opt_verbose_big
TestOptions().parseOptions()
# Invoke with -v

Traceback:

Traceback (most recent call last):
  File "/tmp/twistedOptions.py", line 29, in <module>
    TestOptions().parseOptions()
  File "<path>/twisted/python/usage.py", line 216, in parseOptions
    if isinstance(self._dispatch[optMangled], CoerceParameter):
KeyError: 'verbose_big'

Patch:

--- <path>/lib/python/twisted/python/usage.py        2011-02-09 08:35:08.000000000 -0500
+++ /tmp/usage.py       2011-02-09 08:35:02.000000000 -0500
@@ -393,5 +393,5 @@
             if method not in reverse_dct:
                 reverse_dct[method] = []
-            reverse_dct[method].append(name)
+            reverse_dct[method].append(name.replace('_','-'))

         cmpLength = lambda a, b: cmp(len(a), len(b))

Python 2.6.2

Twisted 8.2.0

Change History (6)

comment:1 Changed 4 years ago by exarkun

  • Author set to exarkun
  • Branch set to branches/underscore-options-4858

(In [30648]) Branching to 'underscore-options-4858'

comment:2 Changed 4 years ago by exarkun

(In [30649]) Apply the fix suggested in the ticket description, as well as a unit test. Also document how Options works a little bit, and remove some old unittesty cruft.

refs #4858

comment:3 Changed 4 years ago by exarkun

  • Author changed from exarkun to t_venkatesh, exarkun
  • Keywords review added

comment:4 Changed 4 years ago by glyph

  • Keywords review removed
  • Owner set to exarkun

Looks great, please merge.

comment:5 Changed 4 years ago by exarkun

  • Resolution set to fixed
  • Status changed from new to closed

(In [30750]) Merge underscore-options-4858

Author: t_venkatesh, exarkun
Reviewer: glyph
Fixes: #4858

Fix a problem in twisted.python.usage handling options with a - in their
name which also have an alias which resulted in an unhandled exception
being raised when those options were parsed.

comment:6 Changed 4 years ago by <automation>

  • Owner exarkun deleted
Note: See TracTickets for help on using tickets.