Opened 11 years ago

Closed 11 years ago

#4858 defect closed fixed (fixed)

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

Reported by: Venkatesh Thirumale Owned by:
Priority: normal Milestone:
Component: core Keywords:
Cc: Branch: branches/underscore-options-4858
branch-diff, diff-cov, branch-cov, buildbot
Author: t_venkatesh, exarkun


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
# Invoke with -v


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


--- <path>/lib/python/twisted/python/        2011-02-09 08:35:08.000000000 -0500
+++ /tmp/       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 11 years ago by Jean-Paul Calderone

Author: exarkun
Branch: branches/underscore-options-4858

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

comment:2 Changed 11 years ago by Jean-Paul Calderone

(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 11 years ago by Jean-Paul Calderone

Author: exarkunt_venkatesh, exarkun
Keywords: review added

comment:4 Changed 11 years ago by Glyph

Keywords: review removed
Owner: set to Jean-Paul Calderone

Looks great, please merge.

comment:5 Changed 11 years ago by Jean-Paul Calderone

Resolution: fixed
Status: newclosed

(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 11 years ago by <automation>

Owner: Jean-Paul Calderone deleted
Note: See TracTickets for help on using tickets.