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

pyright: pin version and turn on reportAssignmentType + reportIndexIssue #2216

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
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,5 @@ jobs:
- uses: jakebailey/pyright-action@v2
with:
python-version: ${{ matrix.python-version }}
version: "1.1.358"
annotate: errors
18 changes: 11 additions & 7 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Notable changes in recent builds.
Notable changes in recent builds.

Maintained by hand, so what's "notable" is subjective! Contributors are
encouraged to add entries for their work.
Expand All @@ -15,14 +15,18 @@ Coming in build 307, as yet unreleased
--------------------------------------

### pywin32
* Fixed non-overriden `pywin.scintilla.formatter.Formatter.ColorizeString` raising `TypeError` instead of `RuntimeError` due to too many parameters (#2216, @Avasam)
* Fixed broken since Python 3 tokenization in `win32comext.axdebug.codecontainer.pySourceCodeContainer.GetSyntaxColorAttributes` (#2216, @Avasam)
* Fixed a `TypeError` due to incorrect kwargs in `win32comext.axscript.client.pydumper.Register` (#2216, @Avasam)
* Fixed error reporting of file copy failure for for installing debug dlls (#2216, @Avasam)
* Fixed `py.exe -m win32verstamp` command and other quote typos caused by Implied String Concatenation (#2225, @Avasam)
* Fixed VT_SAFEARRAY(VT_RECORD) which were missing the last element (#2247)
* Fixed `MFC redist DLLs not found` by preferring corresponding version but accepting different version (#2248, @andreabravetti)
* Fixed `pywintypes.error: (5, 'RegOpenKeyEx', 'Access is denied.')` when running service with debug parameter and no elevation (#2238, @jmartens)
* Fixed handling of `SyntaxError` exception from a Windows Scripting Host Python Script on Python 3.10+ (#2235, @nbbeatty)
* Add `CredGetSessionTypes` support (#2232, @CristiFati)
* Fixed `win32clipboard` increasing size of data when `SetClipboardData` used with `CF_DIB` (#2184, @CristiFati)
* Add `StoreLogoff` to `PyIMsgStore` to prevent possible hang when MAPI uninitializes or during session logoff (#2196, avivbrg)
* Add `StoreLogoff` to `PyIMsgStore` to prevent possible hang when MAPI uninitializes or during session logoff (#2196, @avivbrg)
* Enhance CredDelete to work with dictionaries (#2198, @CristiFati)
* Add UnregisterHotKey support (#2185, @CristiFati)
* IFolderView COM client support (#2180, #2181, #2182, @CristiFati)
Expand Down Expand Up @@ -131,17 +135,17 @@ Coming in build 307, as yet unreleased
* General speed and size improvements due to all the removed code. (#2046, #1986, #2050, #1950, #2085, #2087, #2051, #1990, #2106, #2127, #2124, #2126, #2177, #2218, #2202, #2205, #2217)

### adodbapi
* Remove references to outdated IronPython (#2049)
* Remove references to outdated IronPython (#2049, @Avasam)
This removes the following public names:
* `adodbapi.adodbapi.onWin32`
* `adodbapi.apibase.onIronPython`
* `adodbapi.apibase.NullTypes`
* `adodbapi.apibase.DateTime`
* Remove references to outdated `mxDateTime` (#2048)
* Remove references to outdated `mxDateTime` (#2048, @Avasam)
This removes the following public names:
* `adodbapi.apibase.mxDateTime`
* `adodbapi.apibase.mxDateTimeConverter`
* Removed obsolete Python 2 aliases (#2088)
* Removed obsolete Python 2 aliases (#2088, @Avasam)
This removes the following public names:
* `adodbapi.adodbapi.unicodeType`
* `adodbapi.adodbapi.longType`
Expand All @@ -152,8 +156,8 @@ Coming in build 307, as yet unreleased
* `adodbapi.apibase.StringTypes`
* `adodbapi.apibase.makeByteBuffer`
* `adodbapi.apibase.memoryViewType`
* Remove outdated and unused remote feature (#2098)
* Migrated from `distutils` to `setuptools` (#2133)
* Remove outdated and unused remote feature (#2098, @Avasam)
* Migrated from `distutils` to `setuptools` (#2133, @Avasam)

Build 306, released 2023-03-26
------------------------------
Expand Down
2 changes: 1 addition & 1 deletion Pythonwin/pywin/framework/interact.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def ColorizeInteractiveCode(self, cdoc, styleStart, stylePyStart):
if ch not in "\r\n":
self.ColorSeg(startSeg, i - 1, state)
startSeg = i
if ch in (sys.ps1[0], sys.ps2[0]):
if ch in (str(sys.ps1)[0], str(sys.ps2)[0]):
state = STYLE_INTERACTIVE_PROMPT
elif cdoc[i : i + len(tracebackHeader)] == tracebackHeader:
state = STYLE_INTERACTIVE_ERROR
Expand Down
4 changes: 4 additions & 0 deletions Pythonwin/pywin/framework/startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@
import pywin
import pywin.framework

# Ensure we're working on __path__ as list, not Iterable
pywin.__path__ = list(pywin.__path__)
pywin.framework.__path__ = list(pywin.framework.__path__)

pywin.__path__[0] = win32ui.FullPath(pywin.__path__[0])
pywin.framework.__path__[0] = win32ui.FullPath(pywin.framework.__path__[0])

Expand Down
4 changes: 2 additions & 2 deletions Pythonwin/pywin/scintilla/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ def get_section_header(line):


def find_config_file(f):
return os.path.join(pywin.__path__[0], f + ".cfg")
return os.path.join(next(iter(pywin.__path__)), f + ".cfg")


def find_config_files():
return [
os.path.split(x)[1]
for x in [
os.path.splitext(x)[0]
for x in glob.glob(os.path.join(pywin.__path__[0], "*.cfg"))
for x in glob.glob(os.path.join(next(iter(pywin.__path__)), "*.cfg"))
]
]

Expand Down
2 changes: 1 addition & 1 deletion Pythonwin/pywin/scintilla/formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ def RegisterStyle(self, style, stylenum=None):
self.nextstylenum = self.nextstylenum + 1
FormatterBase.RegisterStyle(self, style, stylenum)

def ColorizeString(self, str, charStart, styleStart):
def ColorizeString(self, str, styleStart):
raise RuntimeError("You must override this method")

def Colorize(self, start=0, end=-1):
Expand Down
2 changes: 1 addition & 1 deletion Pythonwin/pywin/test/test_pywin.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
user_interaction = getattr(__main__, "user_interaction", False) # from all.py maybe
file_abs = os.path.abspath(__file__)
src_dir = os.path.dirname(file_abs)
pywin_path = pywin.__path__[0]
pywin_path = next(iter(pywin.__path__))
pythonwinpy_path = os.path.dirname(pywin_path) + "\\start_pythonwin.py"
Object = argparse.Namespace
_indebugger = "pywin.debugger" in sys.modules
Expand Down
4 changes: 2 additions & 2 deletions Pythonwin/win32uimodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1603,8 +1603,8 @@ static PyObject *ui_set_dialog_bk_color(PyObject *self, PyObject *args)
int clrCtlBk = RGB(192, 192, 192);
int clrCtlText = RGB(0, 0, 0);

// @pyparm int|clrCtlBk|win32ui.RGB(192, 192, 192)|The color for the controls background.
// @pyparm int|clrCtlText|win32ui.RGB(0, 0, 0)|The color for the controls text.
// @pyparm int|clrCtlBk|win32api.RGB(192, 192, 192)|The color for the controls background.
// @pyparm int|clrCtlText|win32api.RGB(0, 0, 0)|The color for the controls text.
if (!PyArg_ParseTuple(args, "|ii:SetDialogBkColor", &clrCtlBk, &clrCtlText))
return NULL;
CProtectedWinApp *pApp = GetProtectedApp();
Expand Down
8 changes: 5 additions & 3 deletions com/win32com/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#
# Initialization for the win32com package
#
from __future__ import annotations

import os
import sys
Expand All @@ -26,6 +27,9 @@
### TODO - Load _all_ \\Extensions subkeys - for now, we only read the default
### Modules will work if loaded into "win32comext" path.

# Ensure we're working on __path__ as list, not Iterable
__path__: list[str] = list(__path__) # type: ignore[no-redef]


def SetupEnvironment():
HKEY_LOCAL_MACHINE = -2147483646 # Avoid pulling in win32con for just these...
Expand Down Expand Up @@ -96,9 +100,7 @@ def __PackageSupportBuildPath__(package_path):
try:
import win32com.gen_py

# hrmph - 3.3 throws: TypeError: '_NamespacePath' object does not support indexing
# attempting to get __path__[0] - but I can't quickly repro this stand-alone.
# Work around it by using an iterator.
# __path__ is only ensured to be an Iterable, not a list.
__gen_path__ = next(iter(sys.modules["win32com.gen_py"].__path__))
except ImportError:
# If a win32com\gen_py directory already exists, then we use it
Expand Down
2 changes: 1 addition & 1 deletion com/win32com/server/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def _find_localserver_exe(mustfind):
def _find_localserver_module():
import win32com.server

path = win32com.server.__path__[0]
path = next(iter(win32com.server.__path__))
baseName = "localserver"
pyfile = os.path.join(path, baseName + ".py")
try:
Expand Down
4 changes: 3 additions & 1 deletion com/win32com/test/GenTestScripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
def GetGenPath():
import win32api

return os.path.join(win32api.GetFullPathName(win32com.test.__path__[0]), genDir)
return os.path.join(
win32api.GetFullPathName(next(iter(win32com.test.__path__))), genDir
)


def GenerateFromRegistered(fname, *loadArgs):
Expand Down
8 changes: 5 additions & 3 deletions com/win32com/test/testAXScript.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
class AXScript(win32com.test.util.TestCase):
def setUp(self):
file = win32api.GetFullPathName(
os.path.join(win32com.axscript.client.__path__[0], "pyscript.py")
os.path.join(next(iter(win32com.axscript.client.__path__)), "pyscript.py")
)
from win32com.test.util import RegisterPythonServer

Expand All @@ -22,7 +22,7 @@ def setUp(self):

def testHost(self):
file = win32api.GetFullPathName(
os.path.join(win32com.axscript.__path__[0], "test\\testHost.py")
os.path.join(next(iter(win32com.axscript.__path__)), "test\\testHost.py")
)
cmd = f'{win32api.GetModuleFileName(0)} "{file}"'
if verbose:
Expand All @@ -31,7 +31,9 @@ def testHost(self):

def testCScript(self):
file = win32api.GetFullPathName(
os.path.join(win32com.axscript.__path__[0], "Demos\\Client\\wsh\\test.pys")
os.path.join(
next(iter(win32com.axscript.__path__)), "Demos\\Client\\wsh\\test.pys"
)
)
cmd = 'cscript.exe "%s"' % (file)
if verbose:
Expand Down
3 changes: 2 additions & 1 deletion com/win32comext/axdebug/codecontainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ def GetSyntaxColorAttributes(self):
self.lastPos = 0
self.attrs = []
try:
tokenize.tokenize(self.GetNextLine, self._ProcessToken)
for tokens in tokenize.tokenize(self.GetNextLine):
self._ProcessToken(*tokens)
Comment on lines +162 to +163
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been broken since Python 3 !

except tokenize.TokenError:
pass # Ignore - will cause all subsequent text to be commented.
numAtEnd = len(self.GetText()) - self.lastPos
Expand Down
4 changes: 2 additions & 2 deletions com/win32comext/axscript/client/pydumper.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ def Register():
RegisterServer(
clsid=clsid,
pythonInstString="win32com.axscript.client.pyscript.PyDumper",
className="Python Debugging/Dumping ActiveX Scripting Engine",
desc="Python Debugging/Dumping ActiveX Scripting Engine",
progID=languageName,
verProgID=verProgId,
catids=categories,
policy=policy,
catids=categories,
dispatcher=dispatcher,
)

Expand Down
2 changes: 1 addition & 1 deletion mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ exclude = (?x)(
| ^Pythonwin/Scintilla/
; Forked IDLE extensions predating Python 2.3. They now live in idlelib in https://github.com/python/cpython/tree/main/Lib/idlelib
| ^Pythonwin/pywin/idle/
; TODO: adodbapi should be updated and fixed separatly
; TODO: adodbapi should be updated and fixed separately
| ^adodbapi/
; TODO: Ignoring non-public APIs until all public API is typed
| ([Tt]est|[Dd]emos?)/
Expand Down
4 changes: 1 addition & 3 deletions pyrightconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,13 @@
"reportAttributeAccessIssue": "none",
// FIXE: These all need to be fixed first and turned back to error
// some of the fixes need to be done in types-pywin32 from typeshed
"reportAssignmentType": "warning",
"reportCallIssue": "warning",
"reportIndexIssue": "warning",
"reportOperatorIssue": "warning",
"reportOptionalCall": "warning",
"reportOptionalIterable": "warning",
"reportOptionalMemberAccess": "warning",
"reportOptionalSubscript": "warning",
// TODO: Leave Unbound/Undefined to its own PR(s)
// TODO: Leave Unbound/Undefined to their own PR(s)
"reportUnboundVariable": "warning",
"reportUndefinedVariable": "warning",
// Too many dynamically generated modules. This will require type stubs to properly fix.
Expand Down
2 changes: 1 addition & 1 deletion win32/scripts/setup_d.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def _docopy(src, dest):
return 1
except:
print(f"Error copying '{src}' -> '{dest}'")
print(str(sys.exc_info[1]))
print(str(sys.exc_info()[1]))
usage_and_die(3)


Expand Down
Loading