Skip to content

Commit

Permalink
various runtime improvements found by type-checking (#2176)
Browse files Browse the repository at this point in the history
  • Loading branch information
Avasam authored Feb 5, 2024
1 parent 93426ff commit 3e9da59
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 36 deletions.
12 changes: 3 additions & 9 deletions Pythonwin/pywin/framework/editor/color/coloreditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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."

Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
4 changes: 1 addition & 3 deletions com/win32com/client/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,7 @@ class NotSupportedException(Exception):
pythoncom.VT_VOID,
]

NoTranslateMap = {}
for v in NoTranslateTypes:
NoTranslateMap[v] = None
NoTranslateMap = set(NoTranslateTypes)


class MapEntry:
Expand Down
4 changes: 1 addition & 3 deletions com/win32com/makegw/makegw.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 1 addition & 4 deletions com/win32com/server/exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
5 changes: 3 additions & 2 deletions isapi/threaded_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
"<PRE>{}<B>{}</B></PRE>".format(
cgi.escape("".join(list[:-1])),
cgi.escape(list[-1]),
cgi.escape("".join(list)),
cgi.escape(bold),
),
file=ecb,
)
Expand Down
9 changes: 1 addition & 8 deletions win32/Lib/pywin32_testutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 4 additions & 3 deletions win32/Lib/win32rcparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -19,6 +17,9 @@
import commctrl
import win32con

__author__ = "Adam Walker"
__version__ = "0.11"

_controlMap = {
"DEFPUSHBUTTON": 0x80,
"PUSHBUTTON": 0x80,
Expand Down Expand Up @@ -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():
Expand Down
5 changes: 3 additions & 2 deletions win32/Lib/win32timezone.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@
datetime.datetime(2011, 11, 6, 1, 0, tzinfo=TimeZoneInfo('Pacific Standard Time'))
"""
__author__ = "Jason R. Coombs <jaraco@jaraco.com>"

import datetime
import logging
Expand All @@ -243,13 +242,15 @@

import win32api

__author__ = "Jason R. Coombs <jaraco@jaraco.com>"

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_):
Expand Down
5 changes: 3 additions & 2 deletions win32/scripts/VersionStamp/BrandProject.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down

0 comments on commit 3e9da59

Please sign in to comment.