Repository: nvaccess/nvda

Issue:
Python 3: dict.has_key is no more
Hi,

Another round of Python 3 compatibility report: dict.has_key is gone.

### Steps to reproduce:
Define a dictionary and try obtainig a key by doing dict.has_key(key).

### Actual behavior:
Attribute error is raised in Python 3.

### Expected behavior:
No errors.

### System configuration
#### NVDA installed/portable/running from source:
Source and installed

#### NVDA version:
master.17384

#### Windows version:
Windows 10 Version 1903

#### Name and version of other software in use when reproducing the issue:
N/A

#### Other information about your system:
N/A

### Other questions
#### Does the issue still occur after restarting your PC?
Yes

#### Have you tried any other versions of NVDA? If so, please report their behaviors.
Source code version of Python 3 NVDA.

### Technical:
dict.has_key is gone. The alternative is key in dict.

Thanks.


Discussion:
If there will be a separate pr for this, I vote for filing it against master. This is because the change is completely compatible with Python 2 and will be merged into threshold when master is merged. When merged into master, it will also get broader testing.
Hi, we may need to wait, as two of the lines affected by this are tied to xrange to range conversion. Thanks.

 

From: Leonard de Ruijter <notifications@github.com> 
Sent: Thursday, May 30, 2019 12:15 PM
To: nvaccess/nvda <nvda@noreply.github.com>
Cc: Joseph Lee <joseph.lee22590@gmail.com>; Author <author@noreply.github.com>
Subject: Re: [nvaccess/nvda] Python 3: dict.has_key is no more (#9640)

 

If there will be a separate pr for this, I vote for filing it against master. This is because the change is completely compatible with Python 2 and will be merged into threshold when master is merged. When merged into master, it will also get broader testing.

—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub <https://github.com/nvaccess/nvda/issues/9640?email_source=notifications&email_token=AB4AXEH6BD7VFPXZEE44Z2LPYARUPA5CNFSM4HQYD672YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODWTH5KA#issuecomment-497450664> , or mute the thread <https://github.com/notifications/unsubscribe-auth/AB4AXEETGSW6QR5UMOPFU33PYARUPANCNFSM4HQYD67Q> .



Resolving patch:
diff --git a/source/NVDAObjects/JAB/__init__.py b/source/NVDAObjects/JAB/__init__.py
--- a/source/NVDAObjects/JAB/__init__.py
+++ b/source/NVDAObjects/JAB/__init__.py
@@ -284,7 +284,7 @@ def _get_states(self):
 		stateString=self.JABStates
 		stateStrings=stateString.split(',')
 		for state in stateStrings:
-			if JABStatesToNVDAStates.has_key(state):
+			if state in JABStatesToNVDAStates:
 				stateSet.add(JABStatesToNVDAStates[state])
 		if "visible" not in stateStrings:
 			stateSet.add(controlTypes.STATE_INVISIBLE)
diff --git a/source/appModules/msimn.py b/source/appModules/msimn.py
--- a/source/appModules/msimn.py
+++ b/source/appModules/msimn.py
@@ -65,7 +65,7 @@ def event_NVDAObject_init(self,obj):
 		parentClassName=winUser.getClassName(parentWindow)
 		#If this object is an email header field, and we have a custom label for it,
 		#Then set the object's name to the label 
-		if parentClassName=="OE_Envelope" and isinstance(obj,IAccessible) and obj.IAccessibleChildID==0 and envelopeNames.has_key(controlID):
+		if parentClassName=="OE_Envelope" and isinstance(obj,IAccessible) and obj.IAccessibleChildID==0 and controlID in envelopeNames:
 			obj.name=envelopeNames[controlID]
 			obj.useITextDocumentSupport=True
 			obj.editValueUnit=textInfos.UNIT_STORY


Test patch: