Repository: nvaccess/nvda

Issue:
Python 3: comparison error in start menu
### Steps to reproduce:
1. Open the Windows 10 1903 start menu from a threshold_py3_staging snapshot
2. Enter a term that doesn't lead to results in the stat menu
2. Press down arrow

### Actual behavior:
The following error is logged:

```
ERROR - scriptHandler.executeScript (14:23:03.058):
error executing script: <bound method EditableText.script_caret_moveByLine of <NVDAObjects.Dynamic_StartMenuSearchFieldSearchFieldEditableTextWithoutAutoSelectDetectionUIA object at 0x043F3E90>> with gesture 'down arrow'
Traceback (most recent call last):
  File "scriptHandler.py", line 189, in executeScript
    script(gesture)
  File "editableText.py", line 187, in script_caret_moveByLine
    self._caretMovementScriptHelper(gesture, textInfos.UNIT_LINE)
  File "editableText.py", line 146, in _caretMovementScriptHelper
    self._caretScriptPostMovedHelper(unit,gesture,newInfo)
  File "editableText.py", line 130, in _caretScriptPostMovedHelper
    speech.speakTextInfo(info, unit=speakUnit, reason=controlTypes.REASON_CARET)
  File "speech\__init__.py", line 768, in speakTextInfo
    textWithFields=info.getTextWithFields(formatConfig)
  File "NVDAObjects\UIA\__init__.py", line 647, in getTextWithFields
    fields=list(self._getTextWithFieldsForUIARange(self.obj.UIAElement,self._rangeObj,formatConfig))
  File "NVDAObjects\UIA\__init__.py", line 637, in _getTextWithFieldsForUIARange
    for field in self._getTextWithFields_text(textRange,formatConfig):
  File "NVDAObjects\UIA\__init__.py", line 461, in _getTextWithFields_text
    field=self._getFormatFieldAtRange(tempRange,formatConfig,ignoreMixedValues=len(furtherUIAFormatUnits)==0)
  File "NVDAObjects\UIA\__init__.py", line 238, in _getFormatFieldAtRange
    if UIAHandler.StyleId_Heading1<=styleIDValue<=UIAHandler.StyleId_Heading9:
TypeError: '<=' not supported between instances of 'int' and 'POINTER(IUnknown)'
```

### Expected behavior:
No error



Discussion:

Resolving patch:
diff --git a/source/NVDAObjects/UIA/__init__.py b/source/NVDAObjects/UIA/__init__.py
--- a/source/NVDAObjects/UIA/__init__.py
+++ b/source/NVDAObjects/UIA/__init__.py
@@ -235,8 +235,10 @@ def _getFormatFieldAtRange(self,textRange,formatConfig,ignoreMixedValues=False):
 					formatField['link']=True
 		if formatConfig["reportHeadings"]:
 			styleIDValue=fetcher.getValue(UIAHandler.UIA_StyleIdAttributeId,ignoreMixedValues=ignoreMixedValues)
-			if UIAHandler.StyleId_Heading1<=styleIDValue<=UIAHandler.StyleId_Heading9: 
-				formatField["heading-level"]=(styleIDValue-UIAHandler.StyleId_Heading1)+1
+			# #9842: styleIDValue can sometimes be a pointer to IUnknown.
+			# In Python 3, comparing an int with a pointer raises a TypeError.
+			if isinstance(styleIDValue, int) and UIAHandler.StyleId_Heading1 <= styleIDValue <= UIAHandler.StyleId_Heading9:
+				formatField["heading-level"] = (styleIDValue - UIAHandler.StyleId_Heading1) + 1
 		if fetchAnnotationTypes:
 			annotationTypes=fetcher.getValue(UIAHandler.UIA_AnnotationTypesAttributeId,ignoreMixedValues=ignoreMixedValues)
 			# Some UIA implementations return a single value rather than a tuple.
diff --git a/source/UIABrowseMode.py b/source/UIABrowseMode.py
--- a/source/UIABrowseMode.py
+++ b/source/UIABrowseMode.py
@@ -156,9 +156,11 @@ def UIAHeadingQuicknavIterator(itemType,document,position,direction="next"):
 		tempInfo=curPosition.copy()
 		tempInfo.expand(textInfos.UNIT_CHARACTER)
 		styleIDValue=getUIATextAttributeValueFromRange(tempInfo._rangeObj,UIAHandler.UIA_StyleIdAttributeId,ignoreMixedValues=True)
-		if (UIAHandler.StyleId_Heading1<=styleIDValue<=UIAHandler.StyleId_Heading9):
-			foundLevel=(styleIDValue-UIAHandler.StyleId_Heading1)+1
-			wantedLevel=int(itemType[7:]) if len(itemType)>7 else None
+		# #9842: styleIDValue can sometimes be a pointer to IUnknown.
+		# In Python 3, comparing an int with a pointer raises a TypeError.
+		if isinstance(styleIDValue, int) and UIAHandler.StyleId_Heading1 <= styleIDValue <= UIAHandler.StyleId_Heading9:
+			foundLevel = (styleIDValue - UIAHandler.StyleId_Heading1) + 1
+			wantedLevel = int(itemType[7:]) if len(itemType) > 7 else None
 			if not wantedLevel or wantedLevel==foundLevel: 
 				if not firstLoop or not position:
 					tempInfo.expand(textInfos.UNIT_PARAGRAPH)


Test patch: