From 3e9da59af065a35485107a688e588690ffd72cdf Mon Sep 17 00:00:00 2001 From: Avasam Date: Mon, 5 Feb 2024 17:20:26 -0500 Subject: [PATCH] various runtime improvements found by type-checking (#2176) --- .../pywin/framework/editor/color/coloreditor.py | 12 +++--------- com/win32com/client/build.py | 4 +--- com/win32com/makegw/makegw.py | 4 +--- com/win32com/server/exception.py | 5 +---- isapi/threaded_extension.py | 5 +++-- win32/Lib/pywin32_testutil.py | 9 +-------- win32/Lib/win32rcparser.py | 7 ++++--- win32/Lib/win32timezone.py | 5 +++-- win32/scripts/VersionStamp/BrandProject.py | 5 +++-- 9 files changed, 20 insertions(+), 36 deletions(-) diff --git a/Pythonwin/pywin/framework/editor/color/coloreditor.py b/Pythonwin/pywin/framework/editor/color/coloreditor.py index 518e2a1528..6818d82502 100644 --- a/Pythonwin/pywin/framework/editor/color/coloreditor.py +++ b/Pythonwin/pywin/framework/editor/color/coloreditor.py @@ -9,7 +9,10 @@ from pywin.debugger import dbgcon from pywin.framework.editor import GetEditorOption from pywin.framework.editor.document import EditorDocumentBase +from pywin.framework.editor.frame import EditorFrame +from pywin.framework.editor.template import EditorTemplateBase from pywin.scintilla import bindings, scintillacon +from pywin.scintilla.view import CScintillaView as SyntEditViewParent # WARNING: Duplicated in document.py and editor.py MSG_CHECK_EXTERNAL_FILE = win32con.WM_USER + 1999 @@ -36,9 +39,6 @@ def FinalizeViewCreation(self, view): self.GetDocTemplate().CheckIDLEMenus(view.idle) -SyntEditViewParent = pywin.scintilla.view.CScintillaView - - class SyntEditView(SyntEditViewParent): "A view of a SyntEdit. Obtains data from document." @@ -571,9 +571,6 @@ def FoldCollapseAllEvent(self, event): win32ui.DoWaitCursor(-1) -from pywin.framework.editor.frame import EditorFrame - - class SplitterFrame(EditorFrame): def OnCreate(self, cs): self.HookCommand(self.OnWindowSplit, win32ui.ID_WINDOW_SPLIT) @@ -584,9 +581,6 @@ def OnWindowSplit(self, id, code): return 1 -from pywin.framework.editor.template import EditorTemplateBase - - class SyntEditTemplate(EditorTemplateBase): def __init__( self, res=win32ui.IDR_TEXTTYPE, makeDoc=None, makeFrame=None, makeView=None diff --git a/com/win32com/client/build.py b/com/win32com/client/build.py index 1035ecdff9..8318b88949 100644 --- a/com/win32com/client/build.py +++ b/com/win32com/client/build.py @@ -69,9 +69,7 @@ class NotSupportedException(Exception): pythoncom.VT_VOID, ] -NoTranslateMap = {} -for v in NoTranslateTypes: - NoTranslateMap[v] = None +NoTranslateMap = set(NoTranslateTypes) class MapEntry: diff --git a/com/win32com/makegw/makegw.py b/com/win32com/makegw/makegw.py index 44050bcfc1..92e3354628 100644 --- a/com/win32com/makegw/makegw.py +++ b/com/win32com/makegw/makegw.py @@ -418,9 +418,7 @@ def _write_gw_cpp(f, interface): // --------------------------------------------------- // // Gateway Implementation -""".format( - name=name, gname=gname, base_name=base_name - ) +""" ) for method in interface.methods: diff --git a/com/win32com/server/exception.py b/com/win32com/server/exception.py index 47e0368506..3004f5f43a 100644 --- a/com/win32com/server/exception.py +++ b/com/win32com/server/exception.py @@ -91,10 +91,7 @@ def __repr__(self): def IsCOMException(t=None): if t is None: t = sys.exc_info()[0] - try: - return issubclass(t, pythoncom.com_error) - except TypeError: # 1.5 in -X mode? - return t is pythoncon.com_error + return issubclass(t, pythoncom.com_error) def IsCOMServerException(t=None): diff --git a/isapi/threaded_extension.py b/isapi/threaded_extension.py index daa2ebd9ae..ecf24c8460 100644 --- a/isapi/threaded_extension.py +++ b/isapi/threaded_extension.py @@ -166,10 +166,11 @@ def HandleDispatchError(self, ecb): list = traceback.format_tb( exc_tb, limit ) + traceback.format_exception_only(exc_typ, exc_val) + bold = list.pop() print( "
{}{}
".format( - cgi.escape("".join(list[:-1])), - cgi.escape(list[-1]), + cgi.escape("".join(list)), + cgi.escape(bold), ), file=ecb, ) diff --git a/win32/Lib/pywin32_testutil.py b/win32/Lib/pywin32_testutil.py index d512404972..4dc33d1ae8 100644 --- a/win32/Lib/pywin32_testutil.py +++ b/win32/Lib/pywin32_testutil.py @@ -207,16 +207,9 @@ class TestSkipped(Exception): pass -# This appears to have been "upgraded" to non-private in 3.11 -try: - TextTestResult = unittest._TextTestResult -except AttributeError: - TextTestResult = unittest.TextTestResult - - # The 'TestResult' subclass that records the failures and has the special # handling for the TestSkipped exception. -class TestResult(TextTestResult): +class TestResult(unittest.TextTestResult): def __init__(self, *args, **kw): super().__init__(*args, **kw) self.skips = {} # count of skips for each reason. diff --git a/win32/Lib/win32rcparser.py b/win32/Lib/win32rcparser.py index 9b909898ec..e76acfc9aa 100644 --- a/win32/Lib/win32rcparser.py +++ b/win32/Lib/win32rcparser.py @@ -7,8 +7,6 @@ This is a parser for Windows .rc files, which are text files which define dialogs and other Windows UI resources. """ -__author__ = "Adam Walker" -__version__ = "0.11" import os import pprint @@ -19,6 +17,9 @@ import commctrl import win32con +__author__ = "Adam Walker" +__version__ = "0.11" + _controlMap = { "DEFPUSHBUTTON": 0x80, "PUSHBUTTON": 0x80, @@ -654,7 +655,7 @@ def GenerateFrozenResource(rc_name, output_name, h_name=None): else: filename = sys.argv[1] if "-v" in sys.argv: - RCParser.debugEnabled = 1 + RCParser.debugEnabled = True print("Dumping all resources in '%s'" % filename) resources = Parse(filename) for id, ddef in resources.dialogs.items(): diff --git a/win32/Lib/win32timezone.py b/win32/Lib/win32timezone.py index 8af89c1df5..d27816ed65 100644 --- a/win32/Lib/win32timezone.py +++ b/win32/Lib/win32timezone.py @@ -231,7 +231,6 @@ datetime.datetime(2011, 11, 6, 1, 0, tzinfo=TimeZoneInfo('Pacific Standard Time')) """ -__author__ = "Jason R. Coombs " import datetime import logging @@ -243,13 +242,15 @@ import win32api +__author__ = "Jason R. Coombs " + log = logging.getLogger(__file__) # A couple of objects for working with objects as if they were native C-type # structures. class _SimpleStruct: - _fields_ = None # must be overridden by subclasses + _fields_ = [] # must be overridden by subclasses def __init__(self, *args, **kw): for i, (name, typ) in enumerate(self._fields_): diff --git a/win32/scripts/VersionStamp/BrandProject.py b/win32/scripts/VersionStamp/BrandProject.py index 2612dbc94b..9fc96033c8 100644 --- a/win32/scripts/VersionStamp/BrandProject.py +++ b/win32/scripts/VersionStamp/BrandProject.py @@ -62,11 +62,12 @@ def usage(msg): if __name__ == "__main__": + import getopt + try: - import getopt opts, args = getopt.getopt(sys.argv[1:], "af:d:r") - except getopts.error as msg: + except getopt.GetoptError as msg: usage(msg) bAuto = bRebrand = 0 stampFiles = []