[merge] put back Option.short_name()

Martin Pool mbp at canonical.com
Wed Jan 10 07:50:51 GMT 2007


On 10 Jan 2007, Alexander Belchenko <bialix at ukr.net> wrote:

> >>> The recent short option changes seemed to go in without a deprecation
> >>> period. Was this intended? Was the SHORT_OPTIONS[] thing not meant for
> >>> plugins to use?
> >> These changes break bzrtools shell, for example, because
> >> Option.short_name is no longer callable.  I think a deprecation period
> >> would be appropriate, unless there are overriding concerns.
> > 
> > OK, we can certainly set .short_name to be callable again -- I guess I
> > will store the value in _short_name and make the method return that.
> > 
> > To support SHORT_OPTIONS we might need a special object that stays in
> > sync with the new stuff.  What did your plugin do with it, James?
> > 
> short options changes also affects on bzr_man.rstx generator.
> This was fixed recently and I add tests.
> So changing them back to callable should trigger my tests.

Yes, I saw that.  It's good to have those tests, which would have helped
me realize not to change it in the first place.

Anyhow, here is a bundle that at least restores the short_name() method
to being callable and fixes the tests.  I would like to merge this for
0.14

I'm not sure how SHORT_OPTIONS should be deprecated -- if plugins are
making arbitrary changes to it or registering new options it may be
complicated.  I'm not going to add a complicated simulation of it until
we know what is needed, but I'll try to fix any broken plugins.

-- 
Martin
-------------- next part --------------
# Bazaar revision bundle v0.8
#
# message:
#   Back out previous incompatible change: Option.short_name is now again
#   a method that returns the short name, if any.
#   
# committer: mbp at sourcefrog.net
# date: Wed 2007-01-10 18:28:57.526999950 +1100

=== modified file bzrlib/option.py
--- bzrlib/option.py
+++ bzrlib/option.py
@@ -112,7 +112,7 @@
 class Option(object):
     """Description of a command line option
     
-    :ivar short_name: If this option has a single-letter name, this is it.
+    :ivar _short_name: If this option has a single-letter name, this is it.
     Otherwise None.
     """
 
@@ -138,13 +138,16 @@
         self.name = name
         self.help = help
         self.type = type
-        self.short_name = short_name
+        self._short_name = short_name
         if type is None:
             assert argname is None
         elif argname is None:
             argname = 'ARG'
         self.argname = argname
 
+    def short_name(self):
+        return self._short_name
+
     def get_negation_name(self):
         if self.name.startswith('no-'):
             return self.name[3:]
@@ -184,7 +187,7 @@
         argname =  self.argname
         if argname is not None:
             argname = argname.upper()
-        yield self.name, self.short_name, argname, self.help
+        yield self.name, self.short_name(), argname, self.help
 
 
 class OptionParser(optparse.OptionParser):
@@ -202,7 +205,7 @@
     parser = OptionParser()
     parser.remove_option('--help')
     for option in options.itervalues():
-        option.add_option(parser, option.short_name)
+        option.add_option(parser, option.short_name())
     return parser
 
 

=== modified file bzrlib/tests/test_options.py
--- bzrlib/tests/test_options.py
+++ bzrlib/tests/test_options.py
@@ -65,9 +65,9 @@
 
     def test_get_short_name(self):
         file_opt = option.Option.OPTIONS['file']
-        self.assertEquals(file_opt.short_name, 'F')
+        self.assertEquals(file_opt.short_name(), 'F')
         force_opt = option.Option.OPTIONS['force']
-        self.assertEquals(force_opt.short_name, None)
+        self.assertEquals(force_opt.short_name(), None)
 
     def test_allow_dash(self):
         """Test that we can pass a plain '-' as an argument."""

=== modified file tools/doc_generate/autodoc_rstx.py
--- tools/doc_generate/autodoc_rstx.py
+++ tools/doc_generate/autodoc_rstx.py
@@ -115,7 +115,7 @@
             l = '        --' + option_name
             if option.type is not None:
                 l += ' ' + option.argname.upper()
-            short_name = option.short_name
+            short_name = option.short_name()
             if short_name:
                 assert len(short_name) == 1
                 l += ', -' + short_name

=== modified directory  // last-changed:mbp at sourcefrog.net-20070110072857-mmf4q
... blq5u67jz0k
# revision id: mbp at sourcefrog.net-20070110072857-mmf4qblq5u67jz0k
# sha1: 97a437e8201611fe41b455a14549553dbb4f7e1d
# inventory sha1: a10400112a85453f77c0e2ec8c530090b17ad6a2
# parent ids:
#   pqm at pqm.ubuntu.com-20070109142832-337c25188ea46f2d
# base id: pqm at pqm.ubuntu.com-20070109142832-337c25188ea46f2d
# properties:
#   branch-nick: options



More information about the bazaar mailing list