After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 402494 - For statement refactoring.
For statement refactoring.
Status: RESOLVED FIXED
Product: orca
Classification: Applications
Component: general
2.17.x
Other All
: Low enhancement
: 2.20.0
Assigned To: Rich Burridge
Orca Maintainers
Depends on:
Blocks:
 
 
Reported: 2007-01-30 16:40 UTC by Rich Burridge
Modified: 2007-03-28 12:25 UTC
See Also:
GNOME target: ---
GNOME version: 2.17/2.18


Attachments
Patch to refactor various for statements. (11.58 KB, patch)
2007-03-07 20:08 UTC, Rich Burridge
committed Details | Review
Patch to fixup the for refactoring in speakMisspeltWord() (1.08 KB, patch)
2007-03-28 00:48 UTC, Rich Burridge
committed Details | Review

Description Rich Burridge 2007-01-30 16:40:41 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.
Comment 1 Rich Burridge 2007-03-07 18:05:55 UTC
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.
Comment 2 Rich Burridge 2007-03-07 20:08:52 UTC
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.
Comment 3 Willie Walker 2007-03-07 20:25:03 UTC
> Will, an eyeball over the diffs would be appreciated too.

Eyeballed.  Certainly makes the changed code easier to read, too.  Thanks!
Comment 4 Rich Burridge 2007-03-27 15:43:19 UTC
Closing as FIXED. If any new problems are found, please reopen.
Comment 5 Willie Walker 2007-03-27 23:58:39 UTC
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.
Comment 6 Rich Burridge 2007-03-28 00:48:38 UTC
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.
Comment 7 Rich Burridge 2007-03-28 00:49:00 UTC
Closing as REFIXED.
Comment 8 Rich Burridge 2007-03-28 00:56:13 UTC
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.
Comment 9 Willie Walker 2007-03-28 12:25:13 UTC
(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!