Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3d7b1a5

Browse files
authored
pythongh-122546: use same filename for different exceptions in new repl (python#123217)
*pythongh-122546: use same filename for different exceptions in new repl* +1
1 parent427b106 commit3d7b1a5

File tree

4 files changed

+14
-10
lines changed

4 files changed

+14
-10
lines changed

‎Lib/_pyrepl/console.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def __init__(
162162
self.can_colorize=_colorize.can_colorize()
163163

164164
defshowsyntaxerror(self,filename=None,**kwargs):
165-
super().showsyntaxerror(**kwargs)
165+
super().showsyntaxerror(filename=filename,**kwargs)
166166

167167
def_excepthook(self,typ,value,tb):
168168
importtraceback

‎Lib/code.py‎

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,7 @@ def showsyntaxerror(self, filename=None, **kwargs):
109109
try:
110110
typ,value,tb=sys.exc_info()
111111
iffilenameandtypisSyntaxError:
112-
# Work hard to stuff the correct filename in the exception
113-
try:
114-
msg, (dummy_filename,lineno,offset,line)=value.args
115-
exceptValueError:
116-
# Not the format we expect; leave it alone
117-
pass
118-
else:
119-
# Stuff in the right filename
120-
value=SyntaxError(msg, (filename,lineno,offset,line))
112+
value.filename=filename
121113
source=kwargs.pop('source',"")
122114
self._showtraceback(typ,value,None,source)
123115
finally:

‎Lib/test/test_pyrepl/test_pyrepl.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,6 +1100,16 @@ def test_not_wiping_history_file(self):
11001100
self.assertIn("spam",output)
11011101
self.assertNotEqual(pathlib.Path(hfile.name).stat().st_size,0)
11021102

1103+
@force_not_colorized
1104+
deftest_correct_filename_in_syntaxerrors(self):
1105+
env=os.environ.copy()
1106+
commands="a b c\nexit()\n"
1107+
output,exit_code=self.run_repl(commands,env=env)
1108+
if"can't use pyrepl"inoutput:
1109+
self.skipTest("pyrepl not available")
1110+
self.assertIn("SyntaxError: invalid syntax",output)
1111+
self.assertIn("<python-input-0>",output)
1112+
11031113
@force_not_colorized
11041114
deftest_proper_tracebacklimit(self):
11051115
env=os.environ.copy()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Consistently use same file name for different exceptions in the new repl.
2+
Patch by Sergey B Kirpichev.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp