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

Commit18c9548

Browse files
authored
gh-111159: FixSyntaxError doctests for non-builtin exception classes (#111541)
1 parenta8e1f47 commit18c9548

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

‎Lib/doctest.py‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1399,10 +1399,14 @@ def __run(self, test, compileflags, out):
13991399
# we don't care about the carets / suggestions / etc
14001400
# We only care about the error message and notes.
14011401
# They start with `SyntaxError:` (or any other class name)
1402+
exception_line_prefixes= (
1403+
f"{exception[0].__qualname__}:",
1404+
f"{exception[0].__module__}.{exception[0].__qualname__}:",
1405+
)
14021406
exc_msg_index=next(
14031407
index
14041408
forindex,lineinenumerate(formatted_ex)
1405-
ifline.startswith(f"{exception[0].__name__}:")
1409+
ifline.startswith(exception_line_prefixes)
14061410
)
14071411
formatted_ex=formatted_ex[exc_msg_index:]
14081412

‎Lib/test/test_doctest.py‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3310,6 +3310,24 @@ def test_syntax_error_with_note(cls, multiline=False):
33103310
raiseexc
33113311

33123312

3313+
deftest_syntax_error_subclass_from_stdlib():
3314+
"""
3315+
`ParseError` is a subclass of `SyntaxError`, but it is not a builtin:
3316+
3317+
>>> test_syntax_error_subclass_from_stdlib()
3318+
Traceback (most recent call last):
3319+
...
3320+
xml.etree.ElementTree.ParseError: error
3321+
error
3322+
Note
3323+
Line
3324+
"""
3325+
fromxml.etree.ElementTreeimportParseError
3326+
exc=ParseError("error\nerror")
3327+
exc.add_note('Note\nLine')
3328+
raiseexc
3329+
3330+
33133331
deftest_syntax_error_with_incorrect_expected_note():
33143332
"""
33153333
>>> def f(x):
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix:mod:`doctest` for:exc:`SyntaxError` not-builtin subclasses.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2026 Movatter.jp