Merge lp:~evfool/checkbox/secondfix786924 into lp:checkbox

Proposed by Robert Roth
Status: Merged
Merged at revision: 915
Proposed branch: lp:~evfool/checkbox/secondfix786924
Merge into: lp:checkbox
Diff against target: 13 lines (+3/-1)
1 file modified
checkbox_cli/cli_interface.py (+3/-1)
To merge this branch: bzr merge lp:~evfool/checkbox/secondfix786924
Reviewer Review Type Date Requested Status
Marc Tardif (community) Approve
Jeff Lane  Pending
Review via email: mp+62156@code.launchpad.net

Description of the change

Replaced the current string.lowercase[optionindex] option character choice in the CLI interface with the first letter of the option lowercased for each option, so we will have a more natural y) yes n) no instead of a) yes b) no optionlist (fixes bug #786924)

I have changed the fix to iterate over the characters of the option until it finds one that is not used yet in the keys. If all the characters of the option are used, it will find a letter from the alphabet which is not used yet. This should solve the problem for options starting with the same letter, eg "Yes/No/Not tested" will have the options y/n/o.

To post a comment you must log in.
Revision history for this message
Marc Tardif (cr3) wrote :

The count variable can be assigned any integer value between 0 and len(findkey)-1. However, considering len(findkey) > len(option), this code is likely to result in a IndexError exception:

  key = option[count].lower()

Also, instead of using a count variable, you might like to try something like:

  for key in option.lower() + string.lowercase:
    if key not in self.keys:
      break

review: Needs Fixing
lp:~evfool/checkbox/secondfix786924 updated
915. By Robert Roth

Fixed indexerror in case of falling back to alphabet

Revision history for this message
Robert Roth (evfool) wrote :

Yes, I've missed that, as I first implemented iterating over the options chars and added the alphabet fallback later. Fixed it based on your suggestions. I wanted to avoid break, but in this case it seems to be a bit better. I've also added another variable to avoid converting to lowercase and concatenating the strings in each step. See the branch for the changes.

Revision history for this message
Marc Tardif (cr3) wrote :

First, you don't need to declare and assign the count variable anymore. Second, for i in expression doesn't evaluate the expression on each iteration, so you don't need the findkey variable either. On a last note, I think that the for loop is pretty clear to not need such a large comment. I'll leave that to your discretion though.

review: Needs Fixing
lp:~evfool/checkbox/secondfix786924 updated
916. By Robert Roth

Fixed small problems based on suggestions

917. By Robert Roth

Unnecessary comment removed

Revision history for this message
Robert Roth (evfool) wrote :

Fixed the minor problems based on Marc's comments.

Revision history for this message
Marc Tardif (cr3) wrote :

Looks good, merging!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'checkbox_cli/cli_interface.py'
2--- checkbox_cli/cli_interface.py 2010-11-25 18:15:08 +0000
3+++ checkbox_cli/cli_interface.py 2011-05-25 06:33:30 +0000
4@@ -145,7 +145,9 @@
5
6 def add_option(self, option, key=None):
7 if key is None:
8- key = string.lowercase[len(self.keys)]
9+ for key in option.lower()+string.lowercase:
10+ if key not in self.keys:
11+ break
12 self.keys.append(key)
13 self.options.append(option)
14

Subscribers

People subscribed via source and target branches