From d3c502b2a3034dffd0fc57dfe9a386b6ed123f5e Mon Sep 17 00:00:00 2001 From: Avasam Date: Fri, 11 Aug 2023 14:24:02 -0400 Subject: [PATCH] checkers fixes --- com/win32com/server/exception.py | 12 ++++++------ com/win32comext/adsi/__init__.py | 3 ++- com/win32comext/axdebug/codecontainer.py | 1 - mypy.ini | 3 ++- pyrightconfig.json | 2 -- 5 files changed, 10 insertions(+), 11 deletions(-) diff --git a/com/win32com/server/exception.py b/com/win32com/server/exception.py index 3caedb2d89..25496556ae 100644 --- a/com/win32com/server/exception.py +++ b/com/win32com/server/exception.py @@ -14,12 +14,12 @@ """ import sys -from pythoncom import GetScodeString, com_error +import pythoncom # Note that we derive from com_error, which derives from exceptions.Exception # Also note that we dont support "self.args", as we dont support tuple-unpacking -class COMException(com_error): +class COMException(pythoncom.com_error): """An Exception object that is understood by the framework. If the framework is presented with an exception of type class, @@ -68,14 +68,14 @@ def __init__( if scode == 1 and not self.description: self.description = "S_FALSE" elif scode and not self.description: - self.description = GetScodeString(scode) + self.description = pythoncom.GetScodeString(scode) self.source = source self.helpfile = helpfile self.helpcontext = helpContext # todo - fill in the exception value - com_error.__init__(self, scode, self.description, None, -1) + pythoncom.com_error.__init__(self, scode, self.description, None, -1) def __repr__(self): return "" % (self.scode, self.description) @@ -91,9 +91,9 @@ def IsCOMException(t=None): if t is None: t = sys.exc_info()[0] try: - return issubclass(t, com_error) + return issubclass(t, pythoncom.com_error) except TypeError: # 1.5 in -X mode? - return t is com_error + return t is pythoncom.com_error def IsCOMServerException(t=None): diff --git a/com/win32comext/adsi/__init__.py b/com/win32comext/adsi/__init__.py index b1d7f55368..daca0bd3b8 100644 --- a/com/win32comext/adsi/__init__.py +++ b/com/win32comext/adsi/__init__.py @@ -25,7 +25,7 @@ # interface, as well as via IDispatch. import pythoncom -from .adsi import ( # nopycln: import # win32comext/adsi/adsi.pyd +from .adsi import ( # win32comext/adsi/adsi.pyd ADsBuildEnumerator as PYD_ADsBuildEnumerator, ADsEnumerateNext as PYD_ADsEnumerateNext, ADsGetObject as PYD_ADsGetObject, @@ -111,6 +111,7 @@ def QueryInterface(self, iid): return _get_good_ret(ret) +# We override the adsi.pyd methods to do the right thing. def ADsGetObject(path, iid=pythoncom.IID_IDispatch): ret = PYD_ADsGetObject(path, iid) return _get_good_ret(ret) diff --git a/com/win32comext/axdebug/codecontainer.py b/com/win32comext/axdebug/codecontainer.py index 0fc18ff788..63d8bdd6d3 100644 --- a/com/win32comext/axdebug/codecontainer.py +++ b/com/win32comext/axdebug/codecontainer.py @@ -6,7 +6,6 @@ import sys import tokenize -from typing import Any, cast import win32api import winerror diff --git a/mypy.ini b/mypy.ini index d4d961e21d..01fd376db6 100644 --- a/mypy.ini +++ b/mypy.ini @@ -16,7 +16,8 @@ disallow_incomplete_defs = false ; attr-defined: Module has no attribute (modules are dynamic) ; method-assign: Cannot assign to a method (lots of monkey patching) -disable_error_code = attr-defined, method-assign +; name-defined: Name "..." is not defined (dynamic modules will be hard to type without stubs, ie: pythoncom.*, leave undefined/unbound to Flake8/Ruff/pyright) +disable_error_code = attr-defined, method-assign, name-defined ; TODO: adodbapi should be updated and fixed separatly ; Pythonwin/Scintilla and Pythonwin/pywin/idle are vendored ; Ignoring non-public apis for now diff --git a/pyrightconfig.json b/pyrightconfig.json index 4b45fa91d4..48ece9d6f9 100644 --- a/pyrightconfig.json +++ b/pyrightconfig.json @@ -1,8 +1,6 @@ { "typeCheckingMode": "basic", "pythonVersion": "3.7", - // Ignore shipped types-pywin32 - // "typeshedPath": ".", // Keep it simple for now by allowing both mypy and pyright to use `type: ignore` "enableTypeIgnoreComments": true, // Exclude from scanning when running pyright