Skip to content

Fix reportUnnecessaryComparison that can be resolved through annotations #2327

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

Merged
Merged
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
8 changes: 7 additions & 1 deletion Pythonwin/pywin/framework/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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=""):
Expand Down Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions Pythonwin/pywin/tools/hierlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
10 changes: 7 additions & 3 deletions com/win32comext/axdebug/codecontainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -26,20 +29,21 @@
class SourceCodeContainer:
def __init__(
self,
text,
text: str | None,
fileName="<Remove Me!>",
sourceContext=0,
startLineNumber=0,
site=None,
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
Expand Down
4 changes: 2 additions & 2 deletions pyrightconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
}
2 changes: 1 addition & 1 deletion win32/Lib/sspi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading