Skip to content

Commit

Permalink
NVDA objects/API handlers/Python 3: add explanatory comments. Re nvac…
Browse files Browse the repository at this point in the history
…cess#7105.

Comment from Reef Turner (NV Access): add explanatory comment, prefixing the comment with '# Py3 review required'. Because some changes are based on another issue (nvaccess#9067, for example), prefix the review comment with issue number references as appropriate.
  • Loading branch information
josephsl committed May 24, 2019
1 parent 3f3fd95 commit 6b66796
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions source/IAccessibleHandler.py
Expand Up @@ -832,6 +832,8 @@ def initialize():
accPropServices=comtypes.client.CreateObject(CAccPropServices)
except (WindowsError,COMError) as e:
log.debugWarning("AccPropServices is not available: %s"%e)
# #9067 (Py3 review required): originally, this calls dict.keys, which in Python 2 returns a list and Python 3 assumes iterators.
# Therefore wrap this around a list call.
for eventType in list(winEventIDsToNVDAEventNames.keys()):
hookID=winUser.setWinEventHook(eventType,eventType,0,cWinEventCallback,0,0,0)
if hookID:
Expand Down
1 change: 1 addition & 0 deletions source/JABHandler.py
Expand Up @@ -5,6 +5,7 @@
#This file is covered by the GNU General Public License.
#See the file COPYING for more details.

# Py3 review required: Python 2 "Queue" vs Python 3 "queue".
import queue
from ctypes import *
from ctypes.wintypes import *
Expand Down
1 change: 1 addition & 0 deletions source/NVDAHelper.py
Expand Up @@ -6,6 +6,7 @@

import os
import sys
# Py3 review required: Python 2 "_winreg" vs Python 3 "winreg".
import winreg
import msvcrt
import versionInfo
Expand Down
5 changes: 5 additions & 0 deletions source/NVDAObjects/IAccessible/__init__.py
Expand Up @@ -848,11 +848,14 @@ def _get_states(self):
except COMError:
log.debugWarning("could not get IAccessible states",exc_info=True)
else:
# Py3 review required: Python 2 "dict.has_key" vs Python 3 "key in dict".
# Also, try splitting this line for improved readability.
states.update(IAccessibleHandler.IAccessibleStatesToNVDAStates[x] for x in (y for y in (1<<z for z in range(32)) if y&IAccessibleStates) if x in IAccessibleHandler.IAccessibleStatesToNVDAStates)
if not hasattr(self.IAccessibleObject,'states'):
# Not an IA2 object.
return states
IAccessible2States=self.IA2States
# Py3 review required: Python 2 "dict.has_key' vs Python 3 "key in dict".
states=states|set(IAccessibleHandler.IAccessible2StatesToNVDAStates[x] for x in (y for y in (1<<z for z in range(32)) if y&IAccessible2States) if x in IAccessibleHandler.IAccessible2StatesToNVDAStates)
# Readonly should override editable
if controlTypes.STATE_READONLY in states:
Expand Down Expand Up @@ -1368,6 +1371,8 @@ def _get_positionInfo(self):
del info['indexInGroup']
del info['similarItemsInGroup']
# 0 means not applicable, so remove it.
# #9067 (Py3 review required): originally this called dict.items, which returns iterators in Python 3.
# Therefore wrap this inside a list call.
for key, val in list(info.items()):
if not val:
del info[key]
Expand Down
1 change: 1 addition & 0 deletions source/NVDAObjects/JAB/__init__.py
Expand Up @@ -284,6 +284,7 @@ def _get_states(self):
stateString=self.JABStates
stateStrings=stateString.split(',')
for state in stateStrings:
# Py3 review required: Python 2 "dict.has_key" vs Python 3 "key in dict".
if state in JABStatesToNVDAStates:
stateSet.add(JABStatesToNVDAStates[state])
if "visible" not in stateStrings:
Expand Down
4 changes: 4 additions & 0 deletions source/NVDAObjects/window/excelCellBorder.py
Expand Up @@ -107,6 +107,8 @@

def getCellBorderStyleDescription(bordersObj,reportBorderColor=False):
d=OrderedDict()
# #9067 (Py3 review required): originally called dict.keys.
# Therefore wrap this inside list call.
for pos in list(bordersIndexLabels.keys()):
border=bordersObj[pos]
if border.lineStyle != xlLineStyleNone:
Expand Down Expand Up @@ -150,6 +152,8 @@ def getCellBorderStyleDescription(bordersObj,reportBorderColor=False):
s.append(_("{desc} up-right and down-right diagonal lines").format(desc=d.get(xlDiagonalUp)))
del d[xlDiagonalUp]
del d[xlDiagonalDown]
# #9067 (Py3 review required): Originally caled dict.items.
# Therefore wrap this inside a list call.
for pos,desc in list(d.items()):
# Translators: border styles in Microsoft Excel.
s.append(_("{desc} {position}").format(
Expand Down
3 changes: 3 additions & 0 deletions source/_UIAHandler.py
Expand Up @@ -237,7 +237,10 @@ def MTAThreadFunc(self):
self.reservedNotSupportedValue=self.clientObject.ReservedNotSupportedValue
self.ReservedMixedAttributeValue=self.clientObject.ReservedMixedAttributeValue
self.clientObject.AddFocusChangedEventHandler(self.baseCacheRequest,self)
# #9067 (Py3 review required): originally called dict.keys.
# Therefore wrap this inside a list call.
self.clientObject.AddPropertyChangedEventHandler(self.rootElement,TreeScope_Subtree,self.baseCacheRequest,self,list(UIAPropertyIdsToNVDAEventNames.keys()))
# #9067 (Py3 review required): because dict.iterkeys returns an iterator, and since that will be the behavior in Python 3 anyway, just use "key in dict",
for x in UIAEventIdsToNVDAEventNames:
self.clientObject.addAutomationEventHandler(x,self.rootElement,TreeScope_Subtree,self.baseCacheRequest,self)
# #7984: add support for notification event (IUIAutomation5, part of Windows 10 build 16299 and later).
Expand Down

0 comments on commit 6b66796

Please sign in to comment.