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

Commit083bf47

Browse files
committed
Minor changes to tiny_run.py, make the error source snippet more useful by adding line numbering and a ">" pointer to the erroneous line, and skip a line before the exception explanation
1 parent20b3455 commit083bf47

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

‎examples/tiny/tiny_run.py‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,18 @@ def main(argv: list[str] | None = None) -> int:
4040
parsed=parse_tiny(source_text)
4141
exceptpp.ParseBaseExceptionasexc:
4242
# Print helpful location info
43-
error_line=exc.lineno
44-
fragment="\n".join(source_text.splitlines()[error_line-3 :error_line+1])
43+
error_lineno=exc.lineno
44+
lineno_len=len(str(error_lineno+1))
45+
*prelude,error_line,postlude=source_text.splitlines()[max(error_lineno-3,0) :error_lineno+1]
46+
fragment="\n".join(
47+
[
48+
*(f"{prelineno:>{lineno_len}}:{line}"forprelineno,lineinenumerate(prelude,start=error_lineno-len(prelude))),
49+
f"{error_lineno:>{lineno_len}}: >{error_line}",
50+
f"{error_lineno+1:>{lineno_len}}:{postlude}",
51+
]
52+
)
4553
print(fragment)
54+
print()
4655
print(exc.explain(depth=0))
4756
return3
4857

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp