pytest-dev / pytest-dev/pytest
Format SyntaxErrors like Tracebacklines
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 14.5k
- Forks
- 3.4k
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 35
Description
Since the Traceback of Errors is already formatted in the FILE:LINE MSG Style which is widely supported by editors/IDEs, I would like that the Information from a SyntaxError is printed in the same style.
Instead of this:
E File "/path/to/project/package/lib.py", line 33
E def load_frontend(name):
E ^
E SyntaxError: invalid syntax
I think, it Should be reported like this:
def load_frontend(name):
^
E SyntaxError: invalid syntax
package/lib.py:33:6: SyntaxError
Since a column is available, the SyntaxError can have the FILE:LINE:COLUMN ERROR Syntax.
I would submit a patch, but I am currently unable to navigate all the wrapping that py.code does. It boils down to something like:
if isinstance(e, SyntaxError):
s+= "\n{0.filename}:{0.lineno:d}:{0.offset:d}: {0.msg}".format(e)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing SyntaxError handling through the py.code wrapping mentioned in the issue, then compare it with the existing traceback formatting path. Done means SyntaxError output includes the source context and a FILE:LINE:COLUMN: SyntaxError line in the requested style, with relevant existing formatting behavior preserved.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- testing-qa
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100