Coder Social home page Coder Social logo

correction-helper's Introduction

correction-helper's People

Contributors

julienpalard avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

correction-helper's Issues

Suggested changes

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

Friendly-traceback : important changes

Items that will affect this project at the next release of Friendly-traceback

The traceback item info["simulated_python_traceback"] used to be a list; it is now a string, like all the other items. This is the only true breaking change. The word "Simulated" has been removed -- so you will no longer need to remove it yourself.

A new header for the "variable info" has been added, in part inspired by your markdown formatter. You are/were inserting something like Variables: before showing the value of the "variables". Since "variables" that are shown can be other types of identifiers (e.g. functions, classes, etc.) and not simply "variables", the new header reflects this. See for example https://aroberge.github.io/friendly-traceback-docs/docs/html/tracebacks_en_3.8.html#indexerror-short-tuple. With the exception of NameError, your code should show exactly the same output as before "as is", but might benefit from making use of this.

This header can be different in the case of a NameError; it can be Perhaps you meant to write one of the following:, when a possible typo is identified, or something like "Type hint found for '{name}' as a local variable." (no tests in documentation yet), which is something that could arise if someone writes this:

a: 3  # not a syntax error!
b = a

In the case of NameError, this new header used to be part of the "variable info" shown; it is now separate so that its appearance can be customized.

Items that should have no immediate impact on this project, but could be of some use

The default formatter has been rewritten nearly from scratch
https://github.com/aroberge/friendly-traceback/blob/master/friendly_traceback/formatters.py

A new public API function, tb_items_to_show(level), makes it possible for custom formatters to easily use the verbosity level selected.

A new public function, run, makes it easier to run scripts using friendly traceback. Examples are to be added (soon) in the documentation. The documentation navigation is broken, as I am in the middle of doing a major reorganisation.

Negative verbosity level values are no longer allowed. A negative value used to indicate that the "true" traceback would be shown instead of the "simulated" one.

The new code has not yet been released on Pypi. I want to give you the chance to avoid breakage in case you do any kind of "live install" of Friendly-traceback.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.