Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/mhammond/pywin32 into dedup…
Browse files Browse the repository at this point in the history
…licate-afxres
  • Loading branch information
Avasam committed Mar 14, 2024
2 parents ec3b6d3 + ad20c9b commit 4931bb1
Show file tree
Hide file tree
Showing 84 changed files with 1,192 additions and 350 deletions.
41 changes: 40 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,52 @@ jobs:
path: |
dist/*.whl
# This job can be run locally with the `format_all.bat` script
checkers:
runs-on: ubuntu-latest
runs-on: windows-2019
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
# This job only needs to target the oldest supported version (black@stable supports Python >=3.8)
python-version: '3.8'
- run: pip install isort pycln
- run: pycln . --config=pycln.toml --check
- run: isort . --diff --check-only
- uses: psf/black@stable
with:
options: "--fast --check --diff --verbose"

mypy:
runs-on: windows-2019
strategy:
fail-fast: false
matrix:
# mypy 1.5 dropped support for python 3.7
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- run: pip install types-regex types-setuptools mypy>=1.5
- run: mypy . --python-version=${{ matrix.python-version }}

pyright:
runs-on: windows-2019
strategy:
fail-fast: false
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12']
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
# pyright vendors typeshed, but let's make sure we have the most up to date stubs
- run: pip install types-regex types-setuptools
- uses: jakebailey/pyright-action@v2
with:
python-version: ${{ matrix.python-version }}
annotate: errors

2 changes: 1 addition & 1 deletion Pythonwin/pywin/Demos/app/basictimerapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import win32api
import win32con
import win32ui
from pywin.framework import cmdline, dlgappcore
from pywin.framework import dlgappcore


class TimerAppDialog(dlgappcore.AppDialog):
Expand Down
1 change: 0 additions & 1 deletion Pythonwin/pywin/Demos/app/customprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

# This sample was contributed by Roger Burnham.

import win32api
import win32con
import win32ui
from pywin.framework import app
Expand Down
4 changes: 2 additions & 2 deletions Pythonwin/pywin/Demos/app/dlgappdemo.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import sys

import win32ui
from pywin.framework import app, dlgappcore
from pywin.framework import dlgappcore


class TestDialogApp(dlgappcore.DialogApp):
Expand Down Expand Up @@ -43,7 +43,7 @@ def write(self, str):
win32ui.OutputDebug("dlgapp - no edit control! >>\n%s\n<<\n" % str)


app.AppBuilder = TestDialogApp
app = TestDialogApp()

if __name__ == "__main__":
import demoutils
Expand Down
5 changes: 2 additions & 3 deletions Pythonwin/pywin/Demos/app/dojobapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
# pythonwin /app demos\dojobapp.py


import win32api
import win32con
import win32ui
from pywin.framework import app, dlgappcore
from pywin.framework import dlgappcore


class DoJobAppDialog(dlgappcore.AppDialog):
Expand Down Expand Up @@ -57,7 +56,7 @@ def __init__(self):
DoJobDialogApp.__init__(self)


app.AppBuilder = DoJobDialogApp
app = DoJobDialogApp()


def t():
Expand Down
28 changes: 0 additions & 28 deletions Pythonwin/pywin/framework/app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# App.py
# Application stuff.
# The application is responsible for managing the main frame window.
#
Expand All @@ -17,29 +16,6 @@

from . import scriptutils

## NOTE: App and AppBuild should NOT be used - instead, you should contruct your
## APP class manually whenever you like (just ensure you leave these 2 params None!)
## Whoever wants the generic "Application" should get it via win32iu.GetApp()

# These are "legacy"
AppBuilder = None
App = None # default - if used, must end up a CApp derived class.


# Helpers that should one day be removed!
def AddIdleHandler(handler):
print(
"app.AddIdleHandler is deprecated - please use win32ui.GetApp().AddIdleHandler() instead."
)
return win32ui.GetApp().AddIdleHandler(handler)


def DeleteIdleHandler(handler):
print(
"app.DeleteIdleHandler is deprecated - please use win32ui.GetApp().DeleteIdleHandler() instead."
)
return win32ui.GetApp().DeleteIdleHandler(handler)


# Helper for writing a Window position by name, and later loading it.
def SaveWindowSize(section, rect, state=""):
Expand Down Expand Up @@ -169,10 +145,6 @@ def ExitInstance(self):
if self._obj_:
self._obj_.AttachObject(None)
self._obj_ = None
global App
global AppBuilder
App = None
AppBuilder = None
return 0

def HaveIdleHandler(self, handler):
Expand Down
2 changes: 1 addition & 1 deletion Pythonwin/pywin/framework/bitmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def MatchDocType(self, fileName, fileType):

# For debugging purposes, when this module may be reloaded many times.
try:
win32ui.GetApp().RemoveDocTemplate(bitmapTemplate)
win32ui.GetApp().RemoveDocTemplate(bitmapTemplate) # type: ignore[has-type, used-before-def]
except NameError:
pass

Expand Down
14 changes: 4 additions & 10 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 Expand Up @@ -644,7 +638,7 @@ def GetPythonPropertyPages(self):

# For debugging purposes, when this module may be reloaded many times.
try:
win32ui.GetApp().RemoveDocTemplate(editorTemplate)
win32ui.GetApp().RemoveDocTemplate(editorTemplate) # type: ignore[has-type, used-before-def]
except NameError:
pass

Expand Down
2 changes: 1 addition & 1 deletion Pythonwin/pywin/framework/editor/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ def Create(fileName=None, title=None, template=None):
if __name__ == prefModule:
# For debugging purposes, when this module may be reloaded many times.
try:
win32ui.GetApp().RemoveDocTemplate(editorTemplate)
win32ui.GetApp().RemoveDocTemplate(editorTemplate) # type: ignore[has-type, used-before-def]
except (NameError, win32ui.error):
pass

Expand Down
4 changes: 0 additions & 4 deletions Pythonwin/pywin/framework/intpyapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,8 +551,4 @@ def OnHelpIndex(self, id, code):
help.SelectAndRunHelpFile()


# As per the comments in app.py, this use is depreciated.
# app.AppBuilder = InteractivePythonApp

# Now all we do is create the application
thisApp = InteractivePythonApp()
2 changes: 1 addition & 1 deletion Pythonwin/pywin/framework/mdi_pychecker.py
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,7 @@ def getNew(self):


try:
win32ui.GetApp().RemoveDocTemplate(greptemplate)
win32ui.GetApp().RemoveDocTemplate(greptemplate) # type: ignore[has-type, used-before-def]
except NameError:
pass

Expand Down
2 changes: 1 addition & 1 deletion Pythonwin/pywin/framework/sgrepmdi.py
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ def getNew(self):


try:
win32ui.GetApp().RemoveDocTemplate(greptemplate)
win32ui.GetApp().RemoveDocTemplate(greptemplate) # type: ignore[has-type, used-before-def]
except NameError:
pass

Expand Down
14 changes: 0 additions & 14 deletions Pythonwin/pywin/framework/startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,3 @@

# Import the application module.
__import__(moduleName)

try:
win32ui.GetApp()._obj_
# This worked - an app already exists - do nothing more
except (AttributeError, win32ui.error):
# This means either no app object exists at all, or the one
# that does exist does not have a Python class (ie, was created
# by the host .EXE). In this case, we do the "old style" init...
from . import app

if app.AppBuilder is None:
raise TypeError("No application object has been registered")

app.App = app.AppBuilder()
2 changes: 1 addition & 1 deletion Pythonwin/pywin/framework/stdin.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,4 @@ def fake_input(prompt=None):
finally:
get_input_line = input
else:
sys.stdin = Stdin()
sys.stdin = Stdin() # type: ignore[assignment] # Not an actual TextIO
6 changes: 4 additions & 2 deletions Pythonwin/pywin/scintilla/bindings.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import traceback

import win32api
Expand All @@ -13,8 +15,8 @@

next_id = 5000

event_to_commands = {} # dict of integer IDs to event names.
command_to_events = {} # dict of event names to int IDs
event_to_commands: dict[str, int] = {} # dict of event names to IDs
command_to_events: dict[int, str] = {} # dict of IDs to event names


def assign_command_id(event, id=0):
Expand Down
4 changes: 3 additions & 1 deletion Pythonwin/pywin/scintilla/find.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# find.py - Find and Replace
from __future__ import annotations

import win32api
import win32con
import win32ui
Expand Down Expand Up @@ -34,7 +36,7 @@ def __setattr__(self, attr, val):

curDialog = None
lastSearch = defaultSearch = SearchParams()
searchHistory = []
searchHistory: list[str] = []


def ShowFindDialog():
Expand Down
2 changes: 1 addition & 1 deletion Pythonwin/pywin/tools/browseProjects.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def GetText(self):


class HLICLBRItem(hierlist.HierListItem):
def __init__(self, name, file, lineno, suffix=""):
def __init__(self, name: str, file, lineno, suffix=""):
# If the 'name' object itself has a .name, use it. Not sure
# how this happens, but seems pyclbr related.
# See PyWin32 bug 817035
Expand Down
3 changes: 1 addition & 2 deletions Pythonwin/pywin/tools/regpy.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# (sort-of) Registry editor
import commctrl
import dialog
import win32con
import win32ui
from pywin.mfc import dialog


class RegistryControl:
Expand Down
13 changes: 2 additions & 11 deletions com/win32com/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,13 @@ def __WrapDispatch(
userName=None,
resultCLSID=None,
typeinfo=None,
UnicodeToString=None,
clsctx=pythoncom.CLSCTX_SERVER,
WrapperClass=None,
):
"""
Helper function to return a makepy generated class for a CLSID if it exists,
otherwise cope by using CDispatch.
"""
assert UnicodeToString is None, "this is deprecated and will go away"
if resultCLSID is None:
try:
typeinfo = dispatch.GetTypeInfo()
Expand Down Expand Up @@ -110,11 +108,9 @@ def Dispatch(
userName=None,
resultCLSID=None,
typeinfo=None,
UnicodeToString=None,
clsctx=pythoncom.CLSCTX_SERVER,
):
"""Creates a Dispatch based COM object."""
assert UnicodeToString is None, "this is deprecated and will go away"
dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch, userName, clsctx)
return __WrapDispatch(dispatch, userName, resultCLSID, typeinfo, clsctx=clsctx)

Expand All @@ -125,11 +121,9 @@ def DispatchEx(
userName=None,
resultCLSID=None,
typeinfo=None,
UnicodeToString=None,
clsctx=None,
):
"""Creates a Dispatch based COM object on a specific machine."""
assert UnicodeToString is None, "this is deprecated and will go away"
# If InProc is registered, DCOM will use it regardless of the machine name
# (and regardless of the DCOM config for the object.) So unless the user
# specifies otherwise, we exclude inproc apps when a remote machine is used.
Expand Down Expand Up @@ -157,11 +151,8 @@ class CDispatch(dynamic.CDispatch):
if/when possible.
"""

def _wrap_dispatch_(
self, ob, userName=None, returnCLSID=None, UnicodeToString=None
):
assert UnicodeToString is None, "this is deprecated and will go away"
return Dispatch(ob, userName, returnCLSID, None)
def _wrap_dispatch_(self, ob, userName=None, returnCLSID=None):
return Dispatch(ob, userName, returnCLSID)

def __dir__(self):
return dynamic.CDispatch.__dir__(self)
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
Loading

0 comments on commit 4931bb1

Please sign in to comment.