Suggested changes
Opened this issue · 2 comments
Three relatively minor changes should be made to correction_helper.py, two of which would help making this code future proof. I can submit a PR if desired.
Starting with version 0.1.11 of Friendly-traceback (just uploaded to Pypi.org), line 37 of correction_helper.py:
friendly_traceback.explain()
should be replaced by
friendly_traceback.explain_traceback()
See [1] for a reference.
The reason for this change is to avoid the confusion with explain()
as used in a REPL with a slightly different semantic and syntax as shown in [2].
friendly_traceback.explain()
will be removed once it can be confirmed that no user code (HackInScience, Thonny) will be broken as a result.
For future-proofing, line 162 of correction_helper.py:
def friendly_traceback_markdown(info, level=None, include=None):
can/should be replaced by
def friendly_traceback_markdown(info, **ignore):
In Friendly-traceback, a supporting test [3] has been added
which will help ensure that no breaking changes are going to occur in the future. Please feel free to make suggestions if improvements to the new unit tests are needed.
Somewhat related, a new test to ensure that command line arguments are passed properly to a source (as is used in correction_helper.py) has also been added [4].
Lines 171, 172 of correction_helper.py can be eliminated:
if item.name == "simulated_python_traceback":
line = line.replace("Simulated Traceback", "Traceback")
Reason: The word "Simulated" is not longer used, and will not be reintroduced; the item name simulated_python_traceback
will continue to be used. See [5] for an example of explain()
used in a REPL.
[1] https://github.com/aroberge/friendly-traceback/blob/master/friendly_traceback/__init__.py#L33
[2] https://aroberge.github.io/friendly-traceback-docs/docs/html/repl.html
[3] https://github.com/aroberge/friendly-traceback/blob/master/tests/unit/test_formatter.py together with the custom formatter https://github.com/aroberge/friendly-traceback/blob/master/tests/fake_formatter.py
[4] https://github.com/aroberge/friendly-traceback/blob/master/tests/unit/test_source_with_args.py
[5] https://aroberge.github.io/friendly-traceback-docs/docs/html/tracebacks.html
Given that the formatter is specified on the command line, it is not clear to me that line 181
friendly_traceback.set_formatter(friendly_traceback_markdown)
is really needed.
If you replace friendly
by friendly_traceback
in
correction-helper/correction_helper.py
Line 288 in 3650ef8
friendly
. This would likely make tests running significantly faster as you would not need to install many potentially large dependencies such as rich, pygments, colorama, commonmark, etc.