GNOME Bugzilla – Bug 402494
For statement refactoring.
Last modified: 2007-03-28 12:25:13 UTC
I found out recently that something like: for i in range(0, len(keys)): key = keys[i] can simply be replaced with: for key in keys: There are several places in Orca of the non-Pythonic code that we should adjust. I suggest that we re-factor these, but lets leave it to after 2.18.0. has been released.
Potential places where this can be changed are: atspi.py: for i in range(0, len(self.__listeners)): brlmon.py: for i in range(0, len(string)): default.py: for offset in range(0, len(line)): default.py: for i in range(0, len(allTokens)): default.py: for i in range(0, len(keys)): default.py: for i in range(0, len(userAttrList)): default.py: for i in range(0, len(unicodeText)): default.py: for i in range(0, len(rolesList)): default.py: for i in range(0, len(allTokens)): default.py: for i in range(1, len(line)): default.py: for i in range(0, len(line)): default.py: for i in range(0, len(obj.lastSelections)): find.py: for i in range(0, len(context.lines)): find.py: for j in range(0, len(context.lines[i].zones)): find.py: for k in range(0, len(context.lines[i].zones[j].words)): Gecko.py: for offset in range(0, len(text)): Gecko.py: for offset in range(characterOffset, len(text)): gnomespeechfactory.py: for i in range(0, len(oldText)): hierarchical_presenter.py: for i in range(0, len(apps)): hierarchical_presenter.py: for i in range(0, len(self._currentObjectSpecializations)): J2SE-access-bridge.py: for j in range(0, len(item)): keybindings.py: for i in range(0, len(self.keyBindings)): orca_gui_prefs.py: for i in range(0, len(model)): where_am_I.py: for i in range(0, len(line)): where_am_I.py: for i in range(0, len(keys)): where_am_I.py: for i in range(0, len(allTokens)): where_am_I.py: for i in range(0, len(str)): Evolution.py: for i in range(0, len(allLabels)): Evolution.py: for i in range(0, len(allLabels)): Evolution.py: for j in range(0, len(tokens)): Evolution.py: for i in range(0, len(allText)): gaim.py: for i in range(0, len(messageKeys)): gedit.py: for i in range(0, len(allLabels)): gedit.py: for i in range(0, len(allText)): StarOffice.py: for i in range(0, len(links)): StarOffice.py: for i in range(0, len(allLabels)): StarOffice.py: for i in range(0, len(result[0])): StarOffice.py: for i in range(0, len(allLabels)): StarOffice.py: for i in range(0, len(allPanels)): StarOffice.py: for i in range(0, len(allLabels)): I'll now look at each one and see if it's appropriate and generate a patch.
Created attachment 84192 [details] [review] Patch to refactor various for statements. I've committed the patch and given it a bit of testing. I'd appreciate further testing from other. Prepending "[pending]" to the Summary. Will leave it open until I get feedback from others. Will, an eyeball over the diffs would be appreciated too. Thanks.
> Will, an eyeball over the diffs would be appreciated too. Eyeballed. Certainly makes the changed code easier to read, too. Thanks!
Closing as FIXED. If any new problems are found, please reopen.
Shoot. :-( As part of the prep for v2.19.0, I just ran pychecker and came across the following: /usr/lib/python2.5/site-packages/orca/default.py:3972: No global (i) found Looks like the index of 'i' was being used in speakMisspeltWord, but it was refactored out. So...I'm going to reopen this bug. A similar thing seemed to happen in hierarchical_presenter.py: /usr/lib/python2.5/site-packages/orca/hierarchical_presenter.py:112: No global (i) found There's also something that seemed to fall out from the util.py/default.py refactor: /usr/lib/python2.5/site-packages/orca/hierarchical_presenter.py:152: No global (util) found I say don't worry about hierarchical_presenter. We're going to remove it, anyway.
Created attachment 85415 [details] [review] Patch to fixup the for refactoring in speakMisspeltWord() I've committed the patch for the problem in default.py. As for the hierarchical_presenter.py problem. That file has already been removed. Looks like you've got a bogus copy in your workspace. I suggest checking out a fresh clean copy of Orca from SVN trunk/HEAD and rerunning pychecker on that.
Closing as REFIXED.
Looks like I spoke too soon. hierarchical_presenter.py is gone because Will removed it (bug #319778). Either way, those two pychecker problems should now be fixed.
(In reply to comment #8) > Looks like I spoke too soon. hierarchical_presenter.py is gone because Will > removed it (bug #319778). Either way, those two pychecker problems should > now be fixed. Woo woo! Thanks Rich!