diff --git a/Pythonwin/pywin/framework/app.py b/Pythonwin/pywin/framework/app.py index f0c4d6d3eb..4e0f09b943 100644 --- a/Pythonwin/pywin/framework/app.py +++ b/Pythonwin/pywin/framework/app.py @@ -3,9 +3,12 @@ # # We also grab the FileOpen command, to invoke our Python editor " The PythonWin application code. Manages most aspects of MDI, etc " +from __future__ import annotations + import os import sys import traceback +from typing import TYPE_CHECKING import regutil import win32api @@ -16,6 +19,9 @@ from . import scriptutils +if TYPE_CHECKING: + from typing_extensions import Literal + # Helper for writing a Window position by name, and later loading it. def SaveWindowSize(section, rect, state=""): @@ -61,7 +67,7 @@ class MainFrame(window.MDIFrameWnd): win32ui.ID_INDICATOR_COLNUM, ) - def OnCreate(self, cs): + def OnCreate(self, cs) -> Literal[-1, 0, 1]: self._CreateStatusBar() return 0 diff --git a/Pythonwin/pywin/tools/hierlist.py b/Pythonwin/pywin/tools/hierlist.py index 7ec29563a6..1e4f8d7682 100644 --- a/Pythonwin/pywin/tools/hierlist.py +++ b/Pythonwin/pywin/tools/hierlist.py @@ -12,7 +12,7 @@ # If you need to use the Tree Control, you may still find this API a reasonable # choice. However, you should investigate using the tree control directly # to provide maximum flexibility (but with extra work). - +from __future__ import annotations import commctrl import win32api @@ -259,7 +259,7 @@ def GetBitmapColumn(self, item): else: return 4 - def GetSelectedBitmapColumn(self, item): + def GetSelectedBitmapColumn(self, item) -> int | None: return 0 def CheckChangedChildren(self): diff --git a/com/win32comext/axdebug/codecontainer.py b/com/win32comext/axdebug/codecontainer.py index d82ee00089..babbd6fc4b 100644 --- a/com/win32comext/axdebug/codecontainer.py +++ b/com/win32comext/axdebug/codecontainer.py @@ -4,9 +4,12 @@ to color the text, and also how to translate lines into offsets, and back. """ +from __future__ import annotations + import os import sys import tokenize +from typing import Any import win32api import winerror @@ -26,7 +29,7 @@ class SourceCodeContainer: def __init__( self, - text, + text: str | None, fileName="", sourceContext=0, startLineNumber=0, @@ -34,12 +37,13 @@ def __init__( debugDocument=None, ): self.sourceContext = sourceContext # The source context added by a smart host. - self.text = text + self.text: str | None = text if text: self._buildlines() self.nextLineNo = 0 self.fileName = fileName - self.codeContexts = {} + # Any: PyIDispatch type is not statically exposed + self.codeContexts: dict[int, Any] = {} self.site = site self.startLineNumber = startLineNumber self.debugDocument = debugDocument diff --git a/pyrightconfig.json b/pyrightconfig.json index bc3c26fbc0..d90035dc31 100644 --- a/pyrightconfig.json +++ b/pyrightconfig.json @@ -37,6 +37,8 @@ "reportOptionalIterable": "warning", "reportOptionalMemberAccess": "warning", "reportOptionalSubscript": "warning", + // Needs fixes in types-pywin32 and requires Python 3.8 to annotate ambiguous global variables + "reportUnnecessaryComparison": "warning", // TODO: Leave Unbound/Undefined to their own PR(s) "reportUnboundVariable": "warning", "reportUndefinedVariable": "warning", @@ -49,8 +51,6 @@ "reportMissingModuleSource": "none", // External type stubs may not be completable, and this will require type stubs for dynamic modules. "reportMissingTypeStubs": "information", - // Sometimes used for extra runtime safety - "reportUnnecessaryComparison": "warning", // Use Flake8/Pycln/Ruff instead "reportUnusedImport": "none", } diff --git a/win32/Lib/sspi.py b/win32/Lib/sspi.py index 5b62913543..d2658773ac 100644 --- a/win32/Lib/sspi.py +++ b/win32/Lib/sspi.py @@ -26,7 +26,7 @@ def __init__(self): def reset(self): """Reset everything to an unauthorized state""" - self.ctxt = None + self.ctxt: win32security.PyCtxtHandleType | None = None self.authenticated = False self.initiator_name = None self.service_name = None