Skip to content
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
d285d40
Fix Python failure handling in `Pythonwin/pywin/framework/scriptutils…
Avasam Oct 4, 2024
65a61d6
Merge branch 'main' into scriptutils-handle-failure
Avasam Oct 6, 2024
eef71e9
Merge branch 'main' into scriptutils-handle-failure
Avasam Oct 12, 2024
cd90204
Merge branch 'main' into scriptutils-handle-failure
Avasam Oct 13, 2024
a7130ed
Merge branch 'main' of https://github.com/mhammond/pywin32 into scrip…
Avasam Dec 14, 2024
563608f
Merge branch 'main' into scriptutils-handle-failure
Avasam Dec 31, 2024
c73f8a4
Merge branch 'main' into scriptutils-handle-failure
Avasam Jan 4, 2025
4117a63
Merge branch 'main' into scriptutils-handle-failure
Avasam Mar 4, 2025
96dd0b5
Merge branch 'main' of https://github.com/mhammond/pywin32 into scrip…
Avasam Mar 4, 2025
b7e3050
Merge branch 'main' into scriptutils-handle-failure
Avasam Mar 10, 2025
5eb95e8
Merge branch 'main' into scriptutils-handle-failure
Avasam Mar 12, 2025
6f12bcc
Merge branch 'main' into scriptutils-handle-failure
Avasam Mar 19, 2025
bd663c1
Merge branch 'main' into scriptutils-handle-failure
Avasam Mar 26, 2025
ea9cdcc
Merge branch 'main' of https://github.com/mhammond/pywin32 into scrip…
Avasam Apr 30, 2025
d13c488
Remove tb = None
Avasam Apr 30, 2025
46e4931
Merge branch 'main' into scriptutils-handle-failure
Avasam Jul 22, 2025
cec83db
Merge branch 'main' of https://github.com/mhammond/pywin32 into scrip…
Avasam Jul 24, 2025
57756c4
Merge branch 'main' into scriptutils-handle-failure
Avasam Nov 26, 2025
202e1a0
Merge branch 'main' into scriptutils-handle-failure
Avasam Dec 15, 2025
3de0e94
git mv Pythonwin pythonwin
Avasam May 4, 2026
2614963
Merge branch 'main' of https://github.com/mhammond/pywin32 into scrip…
Avasam May 4, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ https://mhammond.github.io/pywin32_installers.html .

Coming in build 311, as yet unreleased
--------------------------------------
* Fixed Python failure handling in Pythonwin and improve error message (#2319, @Avasam)
* Fixed a regression that broke special __dunder__ methods with CoClass. (#1870, #2493, @Avasam, @geppi)

Build 310, released 2025/03/16
Expand Down
22 changes: 11 additions & 11 deletions Pythonwin/pywin/framework/scriptutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
Various utilities for running/importing a script
"""

from __future__ import annotations

import bdb
import linecache
import os
Expand Down Expand Up @@ -547,14 +549,13 @@ def RunTabNanny(filename):
data = newout.getvalue()
if data:
try:
lineno = data.split()[1]
lineno = int(lineno)
lineno = int(data.split()[1])
_JumpToPosition(filename, lineno)
try: # Try and display whitespace
GetActiveEditControl().SCISetViewWS(1)
except:
pass
win32ui.SetStatusText("The TabNanny found trouble at line %d" % lineno)
win32ui.SetStatusText(f"The TabNanny found trouble at line {lineno}")
except (IndexError, TypeError, ValueError):
print("The tab nanny complained, but I can't see where!")
print(data)
Expand Down Expand Up @@ -602,20 +603,19 @@ def JumpToDocument(fileName, lineno=0, col=1, nChars=0, bScrollToTop=0):
return view


def _HandlePythonFailure(what, syntaxErrorPathName=None):
def _HandlePythonFailure(what: str, syntaxErrorPathName: str | None = None):
typ, details, tb = sys.exc_info()
if isinstance(details, SyntaxError):
filename = details.filename
if (not filename or filename == "<string>") and syntaxErrorPathName:
filename = syntaxErrorPathName
try:
msg, (fileName, line, col, text) = details
if (not fileName or fileName == "<string>") and syntaxErrorPathName:
fileName = syntaxErrorPathName
_JumpToPosition(fileName, line, col)
_JumpToPosition(filename, details.lineno, details.offset)
except (TypeError, ValueError):
msg = str(details)
win32ui.SetStatusText(f"Failed to {what} - syntax error - {msg}")
pass
else:
traceback.print_exc()
win32ui.SetStatusText(f"Failed to {what} - {details}")
win32ui.SetStatusText(f"Failed to {what} - {type(details)} - {details}")
tb = None # Clean up a cycle.


Expand Down