Skip to content
Open
Show file tree
Hide file tree
Changes from all 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.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ As of build 305, installation .exe files have been deprecated; see
Coming in build 312, as yet unreleased
--------------------------------------

* Fixed Python failure handling in Pythonwin and improve error message (mhammond#2319, [@Avasam][Avasam])
* Fixed `axdebug` build on Python 3.11+ using CPython's new opaque frame APIs, fixed 64-bit overflow in sourceContext and stack addresses, fixed incorrect step-over and step-out behavior, and fixed `ListEnumeratorGateway.Next()` returning lazy `map` iterator incompatible with C++ COM gateways that require a sequence (mhammond#2723, mhammond#2724, mhammond#2725, [@wxinix-2022][wxinix-2022])
* Removed more leftover obsolete `UNICODE` constants since dropping Python 2 support in `win32ui`, `win32gui` and `win32clipboard` (mhammond#2717, [@Avasam][Avasam])
* Implement COM Records as `[out]` method parameters (mhammond#2708, [@geppi][geppi], [@the-snork][the-snork])
Expand Down
25 changes: 12 additions & 13 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,21 +603,19 @@ def JumpToDocument(fileName, lineno=0, col=1, nChars=0, bScrollToTop=0):
return view


def _HandlePythonFailure(what, syntaxErrorPathName=None):
typ, details, tb = sys.exc_info()
def _HandlePythonFailure(what: str, syntaxErrorPathName: str | None = None) -> None:
details = sys.exc_info()[1]
if isinstance(details, SyntaxError):
filename = details.filename
if (not filename or filename == "<string>") and syntaxErrorPathName:
filename = syntaxErrorPathName
try:
msg, (fileName, line, col, text) = details
Copy link
Copy Markdown
Collaborator Author

@Avasam Avasam Mar 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code would previously have produced:
TypeError: cannot unpack non-iterable SyntaxError object

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}")
tb = None # Clean up a cycle.
win32ui.SetStatusText(f"Failed to {what} - {type(details)} - {details}")
Copy link
Copy Markdown
Collaborator Author

@Avasam Avasam Jul 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deduplicated win32ui.SetStatusText.

I have also considered the following:

Suggested change
win32ui.SetStatusText(f"Failed to {what} - {type(details)} - {details}")
win32ui.SetStatusText(f"Failed to {what} - {details!r}")



# Find the Python TabNanny in either the standard library or the Python Tools/Scripts directory.
Expand Down
Loading