Skip to content

Commit

Permalink
Merge branch 'main' into pyright-unbound-globals
Browse files Browse the repository at this point in the history
  • Loading branch information
Avasam authored Oct 13, 2024
2 parents 6f07361 + a6ca37a commit 305a0a2
Show file tree
Hide file tree
Showing 116 changed files with 29,785 additions and 15,725 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ jobs:
- uses: psf/black@stable
with:
options: "--fast --check --diff --verbose"
- run: | # Too many files to fit in a single command, exclude vendored Scintilla and mapi_headers
- run: | # Too many files to fit in a single command, also exclude vendored Scintilla and MAPIStubLibrary
clang-format --Werror --dry-run $(git ls-files '*.cpp')
clang-format --Werror --dry-run $(git ls-files '*.h' ':!:Pythonwin/Scintilla/' ':!:com/win32comext/mapi/src/mapi_headers/')
clang-format --Werror --dry-run $(git ls-files '*.h' ':!:Pythonwin/Scintilla/' ':!:com/win32comext/mapi/src/MAPIStubLibrary/')
shell: powershell
mypy:
Expand All @@ -145,7 +145,7 @@ jobs:
cache: pip
cache-dependency-path: .github/workflows/main.yml
check-latest: true
- run: pip install types-regex types-setuptools mypy==1.11
- run: pip install types-regex types-setuptools PyOpenGL mypy==1.11
- run: mypy . --python-version=${{ matrix.python-version }}

pyright:
Expand All @@ -164,7 +164,7 @@ jobs:
cache-dependency-path: .github/workflows/main.yml
check-latest: true
# pyright vendors typeshed, but let's make sure we have the most up to date stubs
- run: pip install types-regex types-setuptools
- run: pip install types-regex types-setuptools PyOpenGL
- uses: jakebailey/pyright-action@v2
with:
python-version: ${{ matrix.python-version }}
Expand Down
3 changes: 1 addition & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,8 @@ repos:
# https://github.com/pre-commit/mirrors-clang-format/blob/main/.pre-commit-hooks.yaml#L6
types: [c++]


# Vendored
exclude: ^(com/win32comext/mapi/src/mapi_headers/|Pythonwin/Scintilla/).*$
exclude: ^(com/win32comext/mapi/src/MAPIStubLibrary/|Pythonwin/Scintilla/).*$

ci:
autoupdate_schedule: quarterly
8 changes: 2 additions & 6 deletions AutoDuck/Dump2HHC.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,7 @@ def _urlescape(name):


def _genCategoryHTMLFromDict(dict, output):
keys = list(dict.keys())
keys.sort()
for key in keys:
for key in sorted(dict):
topic = dict[key]
output.write(f'<LI><A HREF="{topic.context}">{topic.name}</A>\n')

Expand Down Expand Up @@ -285,9 +283,7 @@ def genCategoryHTML(output_dir, cats):

def _genItemsFromDict(dict, cat, output, target, do_children=1):
CHM = "mk:@MSITStore:%s.chm::/" % target
keys = list(dict.keys())
keys.sort()
for k in keys:
for k in sorted(dict):
context = dict[k].context
name = dict[k].name
output.write(
Expand Down
8 changes: 2 additions & 6 deletions AutoDuck/InsertExternalOverviews.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,8 @@ def genHTML(doc):
s = ""
for cat in doc:
s += f"<H3>{cat.label}</H3>\n"
dict = {}
for item in cat.overviewItems.items:
dict[item.name] = item.href
keys = list(dict.keys())
keys.sort()
for k in keys:
dict = {item.name: item.href for item in cat.overviewItems.items}
for k in sorted(dict):
s += f'<LI><A HREF="html/{dict[k]}">{k}</A>\n'
return s

Expand Down
4 changes: 2 additions & 2 deletions AutoDuck/py2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def build_module(fp, mod_name):
functions = []
classes = []
constants = []
for name, ob in list(mod.__dict__.items()):
for name, ob in mod.__dict__.items():
if name.startswith("_"):
continue
if hasattr(ob, "__module__") and ob.__module__ != mod_name:
Expand Down Expand Up @@ -139,7 +139,7 @@ def build_module(fp, mod_name):
func_infos = []
# We need to iter the keys then to a getattr() so the funky descriptor
# things work.
for n in list(ob.ob.__dict__.keys()):
for n in ob.ob.__dict__:
o = getattr(ob.ob, n)
if isinstance(o, (types.FunctionType, types.MethodType)):
info = BuildInfo(n, o)
Expand Down
7 changes: 6 additions & 1 deletion CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ Coming in build 309, as yet unreleased
--------------------------------------

* Fixed unbound global variables in `pywin.dialogs.ideoptions.OptionsPropPage`'s `OnFormat*` methods (#2283, @Avasam)
* Fixed `win32timezone.TimeZoneInfo` initialization from a `[DYNAMIC_]TIME_ZONE_INFORMATION` (#2339, @Avasam)
* Added runtime deprecation warning of `win2kras`, use `win32ras` instead (#2356, @Avasam)
* Improved handling of dict iterations and fallbacks (removes Python 2 support code, small general speed improvement) (#2332, #2330, @Avasam)
* Fixed "Open GL Demo" (`Pythonwin/pywin/Demos/openGLDemo.py`) and restore "Font" demo in `Pythonwin/pywin/Demos/guidemo.py` (#2345, @Avasam)
* Fixed accidentally trying to raise an undefined name instead of an `Exception` in `Pythonwin/pywin/debugger/debugger.py` (#2326, @Avasam)

Build 308, released 2024-10-12
------------------------------
Expand Down Expand Up @@ -176,7 +181,7 @@ as the .chm file, certain MAPI libraries etc, and .exe installers.
* Removed redundant and obsolete references to older python unicode compatibility (#2085, @Avasam)
* Use byte-string (`b""`) for constant bytes values instead of superfluous `.encode` calls (#2046, @Avasam)
* Cleaned up unused imports (#1986, #2051, #1990, #2124, #2126, @Avasam)
* Removed duplicated declarations, constants and definitions (#2050 , #1950, #1990, @Avasam)
* Removed duplicated declarations, constants and definitions (#2050, #1950, #1990, @Avasam)
* Small generalized optimization by using augmented assignements (in-place operators) where possible (#2274, @Avasam)
* General speed and size improvements due to all the removed code. (#2046, #1986, #2050, #1950, #2085, #2087, #2051, #1990, #2106, #2127, #2124, #2126, #2177, #2218, #2202, #2205, #2217)

Expand Down
4 changes: 1 addition & 3 deletions Pythonwin/pywin/Demos/app/customprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ def OnDraw(self, dc):
oldPen = None
x, y = self.size
delta = 2
colors = list(self.colors.keys())
colors.sort()
colors *= 2
colors = sorted(self.colors) * 2
for color in colors:
if oldPen is None:
oldPen = dc.SelectObject(self.pens[color])
Expand Down
5 changes: 1 addition & 4 deletions Pythonwin/pywin/Demos/cmdserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ def unregister(self):

def getwriter(self):
"Return the current thread's writer, default sys.stdout"
try:
return self.writers[_thread.get_ident()]
except KeyError:
return self.origStdOut
self.writers.get(_thread.get_ident(), self.origStdOut)

def write(self, str):
"Write to the current thread's writer, default sys.stdout"
Expand Down
53 changes: 13 additions & 40 deletions Pythonwin/pywin/Demos/guidemo.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
import sys

import __main__
import regutil
import win32api
import win32ui
import pywin.dialogs.list

demos = [ # ('Font', 'import fontdemo;fontdemo.FontDemo()'),
demos = [
("Font", "import fontdemo;fontdemo.FontDemo()"),
("Open GL Demo", "import openGLDemo;openGLDemo.test()"),
("Threaded GUI", "import threadedgui;threadedgui.ThreadedDemo()"),
("Tree View Demo", "import hiertest;hiertest.demoboth()"),
Expand All @@ -19,58 +18,32 @@
("OCX Control Demo", "from ocx import ocxtest;ocxtest.demo()"),
("OCX Serial Port Demo", "from ocx import ocxserialtest; ocxserialtest.test()"),
(
"IE4 Control Demo",
"Internet Explorer Control Demo",
'from ocx import webbrowser; webbrowser.Demo("http://www.python.org")',
),
]


def demo():
def _exec_demo(cmd):
try:
# seeif I can locate the demo files.
import fontdemo
except ImportError:
# else put the demos direectory on the path (if not already)
try:
instPath = regutil.GetRegistryDefaultValue(
regutil.BuildDefaultPythonKey() + "\\InstallPath"
)
except win32api.error:
print(
"The InstallPath can not be located, and the Demos directory is not on the path"
)
instPath = "."

demosDir = win32ui.FullPath(instPath + "\\Demos")
for path in sys.path:
if win32ui.FullPath(path) == demosDir:
break
else:
sys.path.append(demosDir)
import fontdemo
exec(cmd)
except Exception as error:
print(f"Demo of {cmd} failed - {type(error)}:{error}")

import sys

def demo():
if "/go" in sys.argv:
for name, cmd in demos:
try:
exec(cmd)
except:
print(f"Demo of {cmd} failed - {sys.exc_info()[0]}:{sys.exc_info()[1]}")
_exec_demo(cmd)
return
# Otherwise allow the user to select the demo to run

import pywin.dialogs.list

while 1:
# Otherwise allow the user to select the demo to run
while True:
rc = pywin.dialogs.list.SelectFromLists("Select a Demo", demos, ["Demo Title"])
if rc is None:
break
title, cmd = demos[rc]
try:
exec(cmd)
except:
print(f"Demo of {title} failed - {sys.exc_info()[0]}:{sys.exc_info()[1]}")
_exec_demo(cmd)


if __name__ == __main__.__name__:
Expand Down
4 changes: 2 additions & 2 deletions Pythonwin/pywin/Demos/ocx/webbrowser.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This demo uses the IE4 Web Browser control.
# This demo uses the Internet Explorer Web Browser control.

# It catches an "OnNavigate" event, and updates the frame title.
# (event stuff by Neil Hodgson)
Expand All @@ -16,7 +16,7 @@
"{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}", 0, 1, 1
)
if WebBrowserModule is None:
raise ImportError("IE4 does not appear to be installed.")
raise ImportError("Internet Explorer does not appear to be installed.")


class MyWebBrowser(activex.Control, WebBrowserModule.WebBrowser):
Expand Down
69 changes: 57 additions & 12 deletions Pythonwin/pywin/Demos/openGLDemo.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,55 @@

import sys

from pywin.mfc import docview

try:
from OpenGL.GL import * # nopycln: import
from OpenGL.GLU import * # nopycln: import
from OpenGL.GL import (
GL_COLOR_BUFFER_BIT,
GL_DEPTH_BUFFER_BIT,
GL_DEPTH_TEST,
GL_MODELVIEW,
GL_PROJECTION,
GL_QUAD_STRIP,
GL_QUADS,
GL_TRIANGLE_FAN,
glBegin,
glClear,
glClearColor,
glClearDepth,
glColor3f,
glEnable,
glEnd,
glFinish,
glLoadIdentity,
glMatrixMode,
glPopMatrix,
glPushMatrix,
glRotatef,
glTranslatef,
glVertex3f,
glViewport,
)
from OpenGL.GLU import (
GLU_FILL,
GLU_SMOOTH,
gluCylinder,
gluNewQuadric,
gluPerspective,
gluQuadricDrawStyle,
gluQuadricNormals,
)
from OpenGL.WGL import (
PIXELFORMATDESCRIPTOR,
ChoosePixelFormat,
DescribePixelFormat,
GetPixelFormat,
SetPixelFormat,
SwapBuffers,
wglCreateContext,
wglDeleteContext,
wglGetCurrentContext,
wglGetCurrentDC,
wglMakeCurrent,
)
except ImportError:
print("The OpenGL extensions do not appear to be installed.")
print("This Pythonwin demo can not run")
Expand All @@ -16,6 +60,7 @@
import win32api
import win32con
import win32ui
from pywin.mfc import docview

PFD_TYPE_RGBA = 0
PFD_TYPE_COLORINDEX = 1
Expand Down Expand Up @@ -117,24 +162,24 @@ def OnEraseBkgnd(self, dc):
# The OpenGL helpers
def _SetupPixelFormat(self):
dc = self.dc.GetSafeHdc()
pfd = CreatePIXELFORMATDESCRIPTOR()
pfd = PIXELFORMATDESCRIPTOR()
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER
pfd.iPixelType = PFD_TYPE_RGBA
pfd.cColorBits = 24
pfd.cDepthBits = 32
pfd.iLayerType = PFD_MAIN_PLANE
pixelformat = ChoosePixelFormat(dc, pfd)
SetPixelFormat(dc, pixelformat, pfd)
self._CreateRGBPalette()
self._CreateRGBPalette(pfd)

def _CreateRGBPalette(self):
dc = self.dc.GetSafeHdc()
n = GetPixelFormat(dc)
pfd = DescribePixelFormat(dc, n)
def _CreateRGBPalette(self, pfd):
hdc = self.dc.GetSafeHdc()
iPixelFormat = GetPixelFormat(hdc)
DescribePixelFormat(hdc, iPixelFormat, pfd.nSize, pfd)
if pfd.dwFlags & PFD_NEED_PALETTE:
n = 1 << pfd.cColorBits
iPixelFormat = 1 << pfd.cColorBits
pal = []
for i in range(n):
for i in range(iPixelFormat):
this = (
ComponentFromIndex(i, pfd.cRedBits, pfd.cRedShift),
ComponentFromIndex(i, pfd.cGreenBits, pfd.cGreenShift),
Expand Down
2 changes: 1 addition & 1 deletion Pythonwin/pywin/debugger/configui.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def OnInitDialog(self):
def OnOK(self):
self.UpdateData()
dirty = 0
for key, val in list(self.items()):
for key, val in self.items():
if key in self.options:
if self.options[key] != val:
self.options[key] = val
Expand Down
15 changes: 7 additions & 8 deletions Pythonwin/pywin/debugger/debugger.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ def DeleteSelected(self):
item_id = self.GetItem(num)[6]
from bdb import Breakpoint

for bplist in list(Breakpoint.bplist.values()):
for bplist in Breakpoint.bplist.values():
for bp in bplist:
if id(bp) == item_id:
self.debugger.clear_break(bp.file, bp.line)
Expand Down Expand Up @@ -869,15 +869,14 @@ def RespondDebuggerState(self, state):
elif state == DBGSTATE_RUNNING: # Code is running under the debugger.
title = " - running"
elif state == DBGSTATE_BREAK: # We are at a breakpoint or stepping or whatever.
if self.bAtException:
if self.bAtPostMortem:
title = " - post mortem exception"
else:
title = " - exception"
else:
if not self.bAtException:
title = " - break"
elif self.bAtPostMortem:
title = " - post mortem exception"
else:
title = " - exception"
else:
raise error("Invalid debugger state passed!")
raise ValueError("Invalid debugger state passed!")
win32ui.GetMainFrame().SetWindowText(
win32ui.LoadString(win32ui.IDR_MAINFRAME) + title
)
Expand Down
Loading

0 comments on commit 305a0a2

Please sign in to comment.