Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run Ruff --fix & --no-qa #16752

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion appveyor/mozillaSyms.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
To update the list of symbols uploaded to Mozilla, see the DLL_NAMES constant below.
"""

import argparse
import os
import subprocess
import sys
Expand Down
4 changes: 2 additions & 2 deletions site_scons/site_tools/doxygen.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ def DoxyfileParse(file_contents):
lex.whitespace = lex.whitespace.replace("\n", "")
lex.escape = ""

lineno = lex.lineno
lineno = lex.lineno # noqa: F841
token = lex.get_token()
key = token # the first token should be a key
last_token = ""
key_token = False
next_key = False
next_key = False # noqa: F841
new_data = True

def append_data(data, key, new_data, token):
Expand Down
1 change: 0 additions & 1 deletion site_scons/site_tools/gettextTool.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
###

import os
import sys

# Get the path to msgfmt.
MSGFMT = os.path.abspath(os.path.join("miscDeps", "tools", "msgfmt.exe"))
Expand Down
2 changes: 1 addition & 1 deletion site_scons/site_tools/msrpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def exists(env):
return midl.exists(env)

def generate(env):
if not 'MIDL' in env:
if 'MIDL' not in env:
from SCons.Tool import midl
midl.generate(env)
env['BUILDERS']['MSRPCStubs']=MSRPCStubs_builder
Expand Down
2 changes: 1 addition & 1 deletion site_scons/site_tools/recursiveInstall.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def RecursiveInstall(env, target, dir):
dir = env.Dir(dir).abspath
target = env.Dir(target).abspath

l = len(dir) + 1
l = len(dir) + 1 # noqa: E741

relnodes = [ n.abspath[l:] for n in nodes ]

Expand Down
8 changes: 4 additions & 4 deletions source/JABHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ def internal_getWindowHandleFromAccContext(vmID,accContext):
return bridgeDll.getHWNDFromAccessibleContext(vmID,topAC)
finally:
bridgeDll.releaseJavaObject(vmID,topAC)
except:
except: # noqa: E722
return None

def getWindowHandleFromAccContext(vmID,accContext):
Expand Down Expand Up @@ -421,7 +421,7 @@ def __del__(self):
if isRunning:
try:
bridgeDll.releaseJavaObject(self.vmID,self.accContext)
except:
except: # noqa: E722
log.debugWarning("Error releasing java object",exc_info=True)


Expand Down Expand Up @@ -795,15 +795,15 @@ def enterJavaWindow_helper(hwnd):
while time.time()<timeout and not eventHandler.isPendingEvents("gainFocus"):
try:
bridgeDll.getAccessibleContextWithFocus(hwnd,byref(vmID),byref(accContext))
except:
except: # noqa: E722
pass
if vmID and accContext:
break
time.sleep(0.01)
if not vmID or not accContext:
try:
bridgeDll.getAccessibleContextFromHWND(hwnd,byref(vmID),byref(accContext))
except:
except: # noqa: E722
return
vmID=vmID.value
vmIDsToWindowHandles[vmID]=hwnd
Expand Down
42 changes: 21 additions & 21 deletions source/NVDAHelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import winKernel
import config

from ctypes import *
from ctypes import * # noqa: F403
from ctypes import (
WINFUNCTYPE,
c_bool,
Expand All @@ -26,7 +26,7 @@
create_unicode_buffer,
windll,
)
from ctypes.wintypes import *
from ctypes.wintypes import * # noqa: F403
from comtypes import BSTR
import winUser
import eventHandler
Expand Down Expand Up @@ -66,7 +66,7 @@

#utility function to point an exported function pointer in a dll to a ctypes wrapped python function
def _setDllFuncPointer(dll,name,cfunc):
cast(getattr(dll,name),POINTER(c_void_p)).contents.value=cast(cfunc,c_void_p).value
cast(getattr(dll,name),POINTER(c_void_p)).contents.value=cast(cfunc,c_void_p).value # noqa: F405

#Implementation of nvdaController methods
@WINFUNCTYPE(c_long,c_wchar_p)
Expand Down Expand Up @@ -190,35 +190,35 @@ def nvdaController_brailleMessage(text: str) -> SystemErrorCodes:
def _lookupKeyboardLayoutNameWithHexString(layoutString):
buf=create_unicode_buffer(1024)
bufSize=c_int(2048)
key=HKEY()
if windll.advapi32.RegOpenKeyExW(winreg.HKEY_LOCAL_MACHINE,u"SYSTEM\\CurrentControlSet\\Control\\Keyboard Layouts\\"+ layoutString,0,winreg.KEY_QUERY_VALUE,byref(key))==0:
key=HKEY() # noqa: F405
if windll.advapi32.RegOpenKeyExW(winreg.HKEY_LOCAL_MACHINE,u"SYSTEM\\CurrentControlSet\\Control\\Keyboard Layouts\\"+ layoutString,0,winreg.KEY_QUERY_VALUE,byref(key))==0: # noqa: F405
try:
if windll.advapi32.RegQueryValueExW(key,u"Layout Display Name",0,None,buf,byref(bufSize))==0:
if windll.advapi32.RegQueryValueExW(key,u"Layout Display Name",0,None,buf,byref(bufSize))==0: # noqa: F405
windll.shlwapi.SHLoadIndirectString(buf.value,buf,1023,None)
return buf.value
if windll.advapi32.RegQueryValueExW(key,u"Layout Text",0,None,buf,byref(bufSize))==0:
if windll.advapi32.RegQueryValueExW(key,u"Layout Text",0,None,buf,byref(bufSize))==0: # noqa: F405
return buf.value
finally:
windll.advapi32.RegCloseKey(key)

@WINFUNCTYPE(c_long,c_wchar_p)
def nvdaControllerInternal_requestRegistration(uuidString):
pid=c_long()
windll.rpcrt4.I_RpcBindingInqLocalClientPID(None,byref(pid))
windll.rpcrt4.I_RpcBindingInqLocalClientPID(None,byref(pid)) # noqa: F405
pid=pid.value
if not pid:
log.error("Could not get process ID for RPC call")
return -1;
return -1
bindingHandle=c_long()
bindingHandle.value=localLib.createRemoteBindingHandle(uuidString)
if not bindingHandle:
log.error("Could not bind to inproc rpc server for pid %d"%pid)
return -1
registrationHandle=c_long()
res=localLib.nvdaInProcUtils_registerNVDAProcess(bindingHandle,byref(registrationHandle))
res=localLib.nvdaInProcUtils_registerNVDAProcess(bindingHandle,byref(registrationHandle)) # noqa: F405
if res!=0 or not registrationHandle:
log.error("Could not register NVDA with inproc rpc server for pid %d, res %d, registrationHandle %s"%(pid,res,registrationHandle))
windll.rpcrt4.RpcBindingFree(byref(bindingHandle))
windll.rpcrt4.RpcBindingFree(byref(bindingHandle)) # noqa: F405
return -1
import appModuleHandler
queueHandler.queueFunction(queueHandler.eventQueue,appModuleHandler.update,pid,helperLocalBindingHandle=bindingHandle,inprocRegistrationHandle=registrationHandle)
Expand Down Expand Up @@ -275,7 +275,7 @@ def nvdaControllerInternal_drawFocusRectNotify(hwnd, left, top, right, bottom):
focus=api.getFocusObject()
if isinstance(focus,Window) and hwnd==focus.windowHandle:
eventHandler.queueEvent("displayModel_drawFocusRectNotify",focus,rect=(left,top,right,bottom))
return 0;
return 0

@WINFUNCTYPE(c_long,c_long,c_long,c_wchar_p)
def nvdaControllerInternal_logMessage(level,pid,message):
Expand Down Expand Up @@ -373,7 +373,7 @@ def nvdaControllerInternal_inputCompositionUpdate(compositionString,selectionSta
def handleInputCandidateListUpdate(candidatesString,selectionIndex,inputMethod):
candidateStrings=candidatesString.split('\n')
import speech
from NVDAObjects.inputComposition import InputComposition, CandidateList, CandidateItem
from NVDAObjects.inputComposition import CandidateItem
focus=api.getFocusObject()
if not (0<=selectionIndex<len(candidateStrings)):
if isinstance(focus,CandidateItem):
Expand Down Expand Up @@ -452,7 +452,7 @@ def handleInputConversionModeUpdate(oldFlags,newFlags,lcid):
for x in range(32):
x=2**x
msgs=inputConversionModeMessages.get(x)
if not msgs: continue
if not msgs: continue # noqa: E701
newOn=bool(newFlags&x)
oldOn=bool(oldFlags&x)
if newOn!=oldOn:
Expand Down Expand Up @@ -523,7 +523,7 @@ def nvdaControllerInternal_inputLangChangeNotify(threadID,hkl,layoutString):
layoutStringCodes.append(stringCode[0:4].rjust(8,'0'))
for stringCode in layoutStringCodes:
inputMethodName=_lookupKeyboardLayoutNameWithHexString(stringCode)
if inputMethodName: break
if inputMethodName: break # noqa: E701
if not inputMethodName:
log.debugWarning("Could not find layout name for keyboard layout, reporting as unknown")
# Translators: The label for an unknown input method when switching input methods.
Expand Down Expand Up @@ -642,7 +642,7 @@ def initialize() -> None:
res=windll.User32.GetKeyboardLayoutNameW(buf)
if res:
lastLayoutString=buf.value
localLib=cdll.LoadLibrary(os.path.join(versionedLibPath,'nvdaHelperLocal.dll'))
localLib=cdll.LoadLibrary(os.path.join(versionedLibPath,'nvdaHelperLocal.dll')) # noqa: F405
for name,func in [
("nvdaController_speakText",nvdaController_speakText),
("nvdaController_speakSsml", nvdaController_speakSsml),
Expand Down Expand Up @@ -670,14 +670,14 @@ def initialize() -> None:
raise e
localLib.nvdaHelperLocal_initialize(globalVars.appArgs.secure)
generateBeep=localLib.generateBeep
generateBeep.argtypes=[c_char_p,c_float,c_int,c_int,c_int]
generateBeep.argtypes=[c_char_p,c_float,c_int,c_int,c_int] # noqa: F405
generateBeep.restype=c_int
onSsmlMarkReached = localLib.nvdaController_onSsmlMarkReached
onSsmlMarkReached.argtypes = [c_wchar_p]
onSsmlMarkReached.restype = c_ulong
# The rest of this function (to do with injection) only applies if NVDA is not running as a Windows store application
# Handle VBuf_getTextInRange's BSTR out parameter so that the BSTR will be freed automatically.
VBuf_getTextInRange = CFUNCTYPE(c_int, c_int, c_int, c_int, POINTER(BSTR), c_int)(
VBuf_getTextInRange = CFUNCTYPE(c_int, c_int, c_int, c_int, POINTER(BSTR), c_int)( # noqa: F405
("VBuf_getTextInRange", localLib),
((1,), (1,), (1,), (2,), (1,)))
if config.isAppX:
Expand All @@ -693,9 +693,9 @@ def initialize() -> None:
winKernel.LOAD_WITH_ALTERED_SEARCH_PATH
)
if not h:
log.critical("Error loading nvdaHelperRemote.dll: %s" % WinError())
log.critical("Error loading nvdaHelperRemote.dll: %s" % WinError()) # noqa: F405
return
_remoteLib=CDLL("nvdaHelperRemote",handle=h)
_remoteLib=CDLL("nvdaHelperRemote",handle=h) # noqa: F405
if _remoteLib.injection_initialize() == 0:
raise RuntimeError("Error initializing NVDAHelperRemote")
if not _remoteLib.installIA2Support():
Expand Down Expand Up @@ -749,6 +749,6 @@ def bstrReturn(address):
# Just access the string ourselves.
# This will terminate at a null character, even though BSTR allows nulls.
# We're only using this for normal, null-terminated strings anyway.
val = wstring_at(address)
val = wstring_at(address) # noqa: F405
windll.oleaut32.SysFreeString(address)
return val
25 changes: 12 additions & 13 deletions source/NVDAObjects/IAccessible/MSHTML.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#This file is covered by the GNU General Public License.
#See the file COPYING for more details.

import time
from comtypes import COMError
import comtypes.client
import comtypes.automation
Expand Down Expand Up @@ -194,7 +193,7 @@ def locateHTMLElementByID(document,ID):
else: #probably IE 10 in standards mode (#3151)
try:
element=document.all.item(ID)
except:
except: # noqa: E722
element=None
if element is None: #getElementsByName doesn't return element with specified ID in IE11 (#5784)
try:
Expand Down Expand Up @@ -230,7 +229,7 @@ def locateHTMLElementByID(document,ID):
if not childElement:
continue
childElement=locateHTMLElementByID(childElement.document,ID)
if not childElement: continue
if not childElement: continue # noqa: E701
return childElement

def getChildHTMLNodeFromFrame(frame):
Expand All @@ -241,7 +240,7 @@ def getChildHTMLNodeFromFrame(frame):
# In this case, just skip this frame.
return
res=IAccessibleHandler.accChild(pacc,1)
if not res: return
if not res: return # noqa: E701
return HTMLNodeFromIAccessible(res[0])

class MSHTMLTextInfo(textInfos.TextInfo):
Expand Down Expand Up @@ -298,7 +297,7 @@ def __init__(self,obj,position,_rangeObj=None):
return
try:
editableBody=self.obj.HTMLNodeName=="BODY" and self.obj.isContentEditable
except:
except: # noqa: E722
editableBody=False
if editableBody:
self._rangeObj=self.obj.HTMLNode.document.selection.createRange()
Expand Down Expand Up @@ -443,7 +442,7 @@ def suspendCaretEvents(self):
self._ignoreCaretEvents=oldVal

def event_caret(self):
if self._ignoreCaretEvents: return
if self._ignoreCaretEvents: return # noqa: E701
if self.TextInfo is not MSHTMLTextInfo and not self._UIAControl:
return
try:
Expand Down Expand Up @@ -475,7 +474,7 @@ def kwargsFromSuper(cls,kwargs,relation=None):
while True:
try:
HTMLNode=HTMLNode.document.activeElement
except:
except: # noqa: E722
log.exception("Error getting activeElement")
break
nodeName=HTMLNode.nodeName or ""
Expand All @@ -496,7 +495,7 @@ def kwargsFromSuper(cls,kwargs,relation=None):
xFactor,yFactor=getZoomFactorsFromHTMLDocument(HTMLNode.document)
try:
HTMLNode=HTMLNode.document.elementFromPoint(p.x // xFactor, p.y // yFactor)
except:
except: # noqa: E722
HTMLNode=None
if not HTMLNode:
log.debugWarning("Error getting HTMLNode with elementFromPoint")
Expand Down Expand Up @@ -847,7 +846,7 @@ def _get_states(self):
def _get_isContentEditable(self):
try:
return bool(self.HTMLNode.isContentEditable)
except:
except: # noqa: E722
return False

def _get_parent(self):
Expand Down Expand Up @@ -936,7 +935,7 @@ def _get_columnNumber(self):
raise NotImplementedError
try:
return self.HTMLNode.cellIndex+1
except:
except: # noqa: E722
raise NotImplementedError

def _get_rowNumber(self):
Expand All @@ -946,7 +945,7 @@ def _get_rowNumber(self):
while HTMLNode:
try:
return HTMLNode.rowIndex+1
except:
except: # noqa: E722
pass
HTMLNode=HTMLNode.parentNode
raise NotImplementedError
Expand All @@ -956,7 +955,7 @@ def _get_rowCount(self):
raise NotImplementedError
try:
return len([x for x in self.HTMLNode.rows])
except:
except: # noqa: E722
raise NotImplementedError

def scrollIntoView(self):
Expand Down Expand Up @@ -1008,7 +1007,7 @@ def _get_table(self):
nodeName=HTMLNode.nodeName
if nodeName:
nodeName=nodeName.upper()
if nodeName=="TABLE": return MSHTML(HTMLNode=HTMLNode)
if nodeName=="TABLE": return MSHTML(HTMLNode=HTMLNode) # noqa: E701
HTMLNode=HTMLNode.parentNode
return None

Expand Down
12 changes: 6 additions & 6 deletions source/NVDAObjects/IAccessible/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,18 @@
from comInterfaces.tom import ITextDocument
from comInterfaces import Accessibility as IA
from comInterfaces import IAccessible2Lib as IA2
import tones
import tones # noqa: F401
import languageHandler
import textInfos.offsets
import textUtils
import colors
import time
import time # noqa: F401
import displayModel
import IAccessibleHandler
import oleacc
import JABHandler
import winUser
import globalVars
import globalVars # noqa: F401
from logHandler import log
import speech
import braille
Expand All @@ -52,10 +52,10 @@
from controlTypes import TextPosition
from controlTypes.formatFields import FontSize, TextAlign
from NVDAObjects.window import Window
from NVDAObjects import NVDAObject, NVDAObjectTextInfo, InvalidNVDAObject
from NVDAObjects import NVDAObject, NVDAObjectTextInfo, InvalidNVDAObject # noqa: F401
import NVDAObjects.JAB
import eventHandler
from NVDAObjects.behaviors import ProgressBar, Dialog, EditableTextWithAutoSelectDetection, FocusableUnfocusableContainer, ToolTip, Notification
from NVDAObjects.behaviors import ProgressBar, Dialog, EditableTextWithAutoSelectDetection, FocusableUnfocusableContainer, ToolTip, Notification # noqa: F401
from locationHelper import RectLTWH
import NVDAHelper

Expand Down Expand Up @@ -2139,7 +2139,7 @@ def _get_name(self):
if name:
#Remove any data after the null character
i=name.find('\0')
if i>=0: name=name[:i]
if i>=0: name=name[:i] # noqa: E701
return name

class TaskList(IAccessible):
Expand Down
Loading