Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
9caa664
Fix all pyright reportOptionalIterable
Avasam Jun 5, 2024
80cddae
Merge branch 'main' into pyright-reportOptionalIterable
Avasam Oct 18, 2024
f1bf8be
Merge branch 'main' of https://github.com/mhammond/pywin32 into pyrig…
Avasam Nov 14, 2024
92aa2c1
Merge branch 'main' of https://github.com/mhammond/pywin32 into pyrig…
Avasam Dec 14, 2024
ed80986
Fix adodbapi issues
Avasam Dec 14, 2024
aa0bcb8
Merge branch 'mhammond:main' into pyright-reportOptionalIterable
Avasam Nov 26, 2025
f4878f6
Use NoReturn for more accurate types
Avasam Nov 26, 2025
fe374e5
Better fixes using generics
Avasam Nov 26, 2025
3947e6f
Discard changes to adodbapi/apibase.py
Avasam Nov 26, 2025
923487e
Merge branch 'pyright-reportOptionalIterable' of https://github.com/A…
Avasam Nov 26, 2025
d8391c2
Correctly re-apply adodbapi.apibase
Avasam Nov 26, 2025
01215b2
Update AutoDuck/document_object.py
Avasam Nov 26, 2025
9d7283a
Discard changes to adodbapi/examples/xls_read.py
Avasam Nov 26, 2025
0694d23
Discard changes to adodbapi/examples/db_print.py
Avasam Nov 26, 2025
33cb9fb
Correctly reapply db_print
Avasam Nov 26, 2025
3a237c8
Merge branch 'main' of https://github.com/mhammond/pywin32 into pyrig…
Avasam Nov 26, 2025
f33783c
assert doc is not None in parseCategories
Avasam Nov 26, 2025
58841d8
Check for None Document earlier
Avasam Nov 26, 2025
9c4a091
Fix new reportIndexIssue
Avasam Nov 26, 2025
afda53d
# incomplete
Avasam Nov 26, 2025
45e2485
Reformat
Avasam Nov 26, 2025
61ca359
git mv Pythonwin pythonwin
Avasam May 4, 2026
028c0c8
Merge branch 'main' of https://github.com/mhammond/pywin32 into pyrig…
Avasam May 4, 2026
e871ee3
Fix ruff check
Avasam May 4, 2026
422dc15
reformat
Avasam May 4, 2026
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
2 changes: 2 additions & 0 deletions AutoDuck/document_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ def GetDocument(fname="pywin32-document.xml"):
handler = categoryHandler()
parser.setContentHandler(handler)
parser.parse(fname)
if handler.document is None:
raise RuntimeError("document was not set by parser")
return handler.document


Expand Down
45 changes: 28 additions & 17 deletions adodbapi/adodbapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
or CPython 3.4 or later.
"""

from __future__ import annotations

__version__ = "2.6.2.0"
version = "adodbapi v" + __version__

Expand All @@ -35,6 +37,8 @@
import os
import sys
import weakref
from collections.abc import Callable, Mapping
from typing import NoReturn

from . import ado_consts as adc, apibase as api, process_connect_string

Expand All @@ -59,9 +63,6 @@ def getIndexedValue(obj, index):
return obj(index)


from collections.abc import Mapping


# ----------------- The .connect method -----------------
def make_COM_connecter():
try:
Expand Down Expand Up @@ -238,7 +239,9 @@ def __init__(self): # now define the instance attributes
self.cursors = weakref.WeakValueDictionary[int, Cursor]()
self.dbms_name = ""
self.dbms_version = ""
self.errorhandler = None # use the standard error handler for this instance
self.errorhandler: (
Callable[[Connection, Cursor, type[api.Error], object], NoReturn] | None
) = None # use the standard error handler for this instance
self.transaction_level = 0 # 0 == Not in a transaction, at the top level
self._autocommit = False

Expand Down Expand Up @@ -401,6 +404,9 @@ def _rollback(self):
except Exception as e:
self._raiseConnectionError(api.ProgrammingError, e)

# TODO: Use a property+setter instead
variantConversions: api.MultiMap

def __setattr__(self, name, value):
if name == "autocommit": # extension: allow user to turn autocommit on or off
if self.supportsTransactions:
Expand Down Expand Up @@ -542,17 +548,21 @@ class Cursor:
## errorhandler...
## allows the programmer to override the connection's default error handler

def __init__(self, connection):
def __init__(self, connection: Connection):
self.command = None
self._ado_prepared = False
self.messages = []
self.messages: list[tuple[type[api.Error], object]] = []
self.connection = connection
self.paramstyle = connection.paramstyle # used for overriding the paramstyle
self._parameter_names = []
self.paramstyle = connection.paramstyle
"""Used for overriding the paramstyle"""
self._parameter_names: list[str] = []
self.recordset_is_remote = False
self.rs = None # the ADO recordset for this cursor
self.converters = [] # conversion function for each column
self.columnNames = {} # names of columns {lowercase name : number,...}
self.rs = None
"""The ADO recordset for this cursor"""
self.converters: list[Callable[[object], object]] = []
"""Conversion function for each column"""
self.columnNames: dict[str, int] = {}
"""Names of columns {lowercase name : number,...}"""
self.numberOfColumns = 0
self._description = None
self.rowcount = -1
Expand Down Expand Up @@ -587,7 +597,9 @@ def __exit__(self, exc_type, exc_val, exc_tb):
"Allow database cursors to be used with context managers."
self.close()

def _raiseCursorError(self, errorclass, errorvalue):
def _raiseCursorError(
self, errorclass: type[api.Error], errorvalue: object
) -> NoReturn:
eh = self.errorhandler
if eh is None:
eh = api.standardErrorHandler
Expand All @@ -613,9 +625,8 @@ def build_column_info(self, recordset):
for i in range(self.numberOfColumns):
f = getIndexedValue(self.rs.Fields, i)
try:
self.converters.append(
varCon[f.Type]
) # conversion function for this column
# conversion function for this column
self.converters.append(varCon[f.Type])
except KeyError:
self._raiseCursorError(
api.InternalError, "Data column of Unknown ADO type=%s" % f.Type
Expand Down Expand Up @@ -716,7 +727,7 @@ def _new_command(self, command_type=adc.adCmdText):

if self.connection is None:
self._raiseCursorError(api.InterfaceError, None)
return
return # Still return in case a custom errorHandler doesn't raise
try:
self.cmd = Dispatch("ADODB.Command")
self.cmd.ActiveConnection = self.connection.connector
Expand Down Expand Up @@ -1036,7 +1047,7 @@ def _fetch(self, limit=None):
self._raiseCursorError(
api.FetchFailedError, "fetch() on closed connection or empty query set"
)
return
return # Still return in case a custom errorHandler doesn't raise

if self.rs.State == adc.adStateClosed or self.rs.BOF or self.rs.EOF:
return list()
Expand Down
9 changes: 7 additions & 2 deletions adodbapi/apibase.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,20 @@
import sys
import time
from collections.abc import Callable, Iterable, Mapping
from typing import TYPE_CHECKING, NoReturn

# noinspection PyUnresolvedReferences
from . import ado_consts as adc

if TYPE_CHECKING:
from adodbapi.adodbapi import Connection, Cursor

verbose = False # debugging flag


# ------- Error handlers ------
def standardErrorHandler(connection, cursor, errorclass, errorvalue):
def standardErrorHandler(
connection: Connection, cursor: Cursor, errorclass: type[Error], errorvalue: object
) -> NoReturn:
err = (errorclass, errorvalue)
try:
connection.messages.append(err)
Expand Down
6 changes: 3 additions & 3 deletions adodbapi/examples/db_print.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
print("")
print("result data description is:")
print(" NAME Type DispSize IntrnlSz Prec Scale Null?")
for d in c.description:
for d in c.description or ():
print(
("%16s %-12s %8s %8d %4d %5d %s")
% (d[0], adc.adTypeNames[d[1]], d[2], d[3], d[4], d[5], bool(d[6]))
Expand All @@ -59,10 +59,10 @@
print("str() of first five records are...")

# get the results
db = c.fetchmany(5)
db_result = c.fetchmany(5)

# print them
for rec in db:
for rec in db_result:
print(rec)

print("")
Expand Down
2 changes: 2 additions & 0 deletions com/win32com/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,8 @@ def register_record_class(cls):
# The base of all makepy generated classes
############################################
class DispatchBaseClass:
Properties_: DispatchBaseClass

def __init__(self, oobj=None):
if oobj is None:
oobj = pythoncom.new(self.CLSID)
Expand Down
11 changes: 9 additions & 2 deletions com/win32com/client/combrowse.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"""

import sys
from typing import Any, TypeVar

import pythoncom
import pywintypes
Expand All @@ -33,8 +34,14 @@
from pywin.tools import browser
from win32com.client import util

# Representing the full set of HLICOM subclasses generics
# would also require statically exposing many types from pythoncom.
# So make the type parameter optional and using `__init__` inference for now,
# and consider relying on typeshed's `pywin32-stubs` later.
_HLICOMT = TypeVar("_HLICOMT", default=Any) # incomplete

class HLIRoot(browser.HLIPythonObject):

class HLIRoot(browser.HLIPythonObject[None]):
def __init__(self, title):
super().__init__(name=title)

Expand All @@ -51,7 +58,7 @@ def __lt__(self, other):
return self.name < other.name


class HLICOM(browser.HLIPythonObject):
class HLICOM(browser.HLIPythonObject[_HLICOMT]):
def GetText(self):
return self.name

Expand Down
4 changes: 4 additions & 0 deletions com/win32com/client/dynamic.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

"""

from __future__ import annotations

import traceback
from itertools import chain
from types import MethodType
Expand Down Expand Up @@ -185,6 +187,8 @@ def DumbDispatch(


class CDispatch:
Properties_: CDispatch

def __init__(self, IDispatch, olerepr, userName=None, lazydata=None):
if userName is None:
userName = "<unknown>"
Expand Down
1 change: 0 additions & 1 deletion pyrightconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
"reportCallIssue": "warning",
"reportOperatorIssue": "warning",
"reportOptionalCall": "warning",
"reportOptionalIterable": "warning",
"reportOptionalMemberAccess": "warning",
"reportOptionalSubscript": "warning",
// Too many dynamically generated modules. This will require type stubs to properly fix.
Expand Down
30 changes: 17 additions & 13 deletions pythonwin/pywin/debugger/debugger.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# debugger.py
"""A debugger for Pythonwin. Built from pdb.

# A debugger for Pythonwin. Built from pdb.
Mark Hammond (MHammond@skippinet.com.au) - Dec 94.

# Mark Hammond (MHammond@skippinet.com.au) - Dec 94.
usage:
>>> import pywin.debugger
>>> pywin.debugger.GetDebugger().run("command")
"""

# usage:
# >>> import pywin.debugger
# >>> pywin.debugger.GetDebugger().run("command")
from __future__ import annotations

import bdb
import os
Expand All @@ -15,6 +16,7 @@
import sys
import traceback
import types
from typing import TypeVar

import commctrl
import pywin.docking.DockingBar
Expand All @@ -28,6 +30,8 @@

from .dbgcon import *

_T = TypeVar("_T")

LVN_ENDLABELEDIT = commctrl.LVN_ENDLABELEDITW


Expand All @@ -44,11 +48,11 @@ def _LineStateToMarker(ls):
return MARKER_BREAKPOINT


class HierListItem(browser.HLIPythonObject):
class HierListItem(browser.HLIPythonObject[_T]):
pass


class HierFrameItem(HierListItem):
class HierFrameItem(HierListItem[types.FrameType]):
def __init__(self, frame, debugger):
HierListItem.__init__(self, frame, repr(frame))
self.debugger = debugger
Expand Down Expand Up @@ -89,16 +93,16 @@ def TakeDefaultAction(self):
return 1


class HierFrameDict(browser.HLIDict):
def __init__(self, dict, name, bitmapColumn):
class HierFrameDict(browser.HLIDict[str, _T]):
def __init__(self, dict: dict[str, _T], name, bitmapColumn):
self.bitmapColumn = bitmapColumn
browser.HLIDict.__init__(self, dict, name)
super().__init__(dict, name)

def GetBitmapColumn(self):
return self.bitmapColumn


class NoStackAvailableItem(HierListItem):
class NoStackAvailableItem(HierListItem[None]):
def __init__(self, why):
HierListItem.__init__(self, None, why)

Expand All @@ -112,7 +116,7 @@ def GetBitmapColumn(self):
return 8


class HierStackRoot(HierListItem):
class HierStackRoot(HierListItem["Debugger"]):
def __init__(self, debugger):
HierListItem.__init__(self, debugger, None)
self.last_stack = []
Expand Down
Loading
Loading