-
Notifications
You must be signed in to change notification settings - Fork 851
Fix Python failure handling in Pythonwin/pywin/framework/scriptutils.py
#2319
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Avasam
wants to merge
21
commits into
mhammond:main
Choose a base branch
from
Avasam:scriptutils-handle-failure
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+13
−13
Open
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 65a61d6
Merge branch 'main' into scriptutils-handle-failure
Avasam eef71e9
Merge branch 'main' into scriptutils-handle-failure
Avasam cd90204
Merge branch 'main' into scriptutils-handle-failure
Avasam a7130ed
Merge branch 'main' of https://github.com/mhammond/pywin32 into scrip…
Avasam 563608f
Merge branch 'main' into scriptutils-handle-failure
Avasam c73f8a4
Merge branch 'main' into scriptutils-handle-failure
Avasam 4117a63
Merge branch 'main' into scriptutils-handle-failure
Avasam 96dd0b5
Merge branch 'main' of https://github.com/mhammond/pywin32 into scrip…
Avasam b7e3050
Merge branch 'main' into scriptutils-handle-failure
Avasam 5eb95e8
Merge branch 'main' into scriptutils-handle-failure
Avasam 6f12bcc
Merge branch 'main' into scriptutils-handle-failure
Avasam bd663c1
Merge branch 'main' into scriptutils-handle-failure
Avasam ea9cdcc
Merge branch 'main' of https://github.com/mhammond/pywin32 into scrip…
Avasam d13c488
Remove tb = None
Avasam 46e4931
Merge branch 'main' into scriptutils-handle-failure
Avasam cec83db
Merge branch 'main' of https://github.com/mhammond/pywin32 into scrip…
Avasam 57756c4
Merge branch 'main' into scriptutils-handle-failure
Avasam 202e1a0
Merge branch 'main' into scriptutils-handle-failure
Avasam 3de0e94
git mv Pythonwin pythonwin
Avasam 2614963
Merge branch 'main' of https://github.com/mhammond/pywin32 into scrip…
Avasam File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -2,6 +2,8 @@ | |||||
| Various utilities for running/importing a script | ||||||
| """ | ||||||
|
|
||||||
| from __future__ import annotations | ||||||
|
|
||||||
| import bdb | ||||||
| import linecache | ||||||
| import os | ||||||
|
|
@@ -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) | ||||||
|
|
@@ -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 | ||||||
| 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}") | ||||||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Deduplicated I have also considered the following:
Suggested change
|
||||||
|
|
||||||
|
|
||||||
| # Find the Python TabNanny in either the standard library or the Python Tools/Scripts directory. | ||||||
|
|
||||||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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