Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display help message upon UndefVarError(:help) using REPL.REPLCompletitions.UndefVarError_hint #41754

Merged
merged 1 commit into from
Aug 14, 2021

Conversation

mkitti
Copy link
Contributor

@mkitti mkitti commented Aug 2, 2021

This is an alternate implementation of #41749 to display a useful help message when the user types "help" or "help()" into the REPL. Rather than creating a new type in InteractiveUtils, this PR modifies the REPL error display by expanding REPL.REPLCompletitions.UndefVarError_hint

In contrast to #41749, this allows the user to create a variable named help. Upon doing so, the help message will not be displayed.

julia> help
ERROR: UndefVarError: help not defined
  Welcome to Julia 1.8.0-DEV.288. The full manual is available at

  https://docs.julialang.org

  as well as many great tutorials and learning resources:

  https://julialang.org/learning/

  For help on a specific function or macro, type ? followed by its name, e.g. ?cos, or ?@time, and press enter. Type ; to enter shell mode, ] to enter package mode.

julia> help()
ERROR: UndefVarError: help not defined
  Welcome to Julia 1.8.0-DEV.288. The full manual is available at

  https://docs.julialang.org

  as well as many great tutorials and learning resources:

  https://julialang.org/learning/

  For help on a specific function or macro, type ? followed by its name, e.g. ?cos, or ?@time, and press enter. Type ; to enter shell mode, ] to enter package mode.
Stacktrace:
 [1] top-level scope
   @ REPL[5]:1

julia> help = 5
5

julia> help
5

This follows the suggestion of @vtjnash to intercept the UnderVarError for help and of @DilumAluthge to implement this functionality in the REPL code.

As shown above, this iteration still shows ERROR: UndefVarError: help not defined upon entering "help" and also shows a stacktrace for help(). A mechanism to hide the error would be nice, but is beyond the scope of this pull request.

@mkitti mkitti changed the title Modify REPL to display mesasge upon receiving UndefVarError(:help), error_display_handler Display help message upon UndefVarError(:help), implement basic REPL.error_display_handler Aug 2, 2021
@DilumAluthge
Copy link
Member

Looks like this somehow broke make docs?

@KristofferC
Copy link
Sponsor Member

KristofferC commented Aug 2, 2021

This new API looks quite a lot like the register_error_hint (

Experimental.register_error_hint(handler, exceptiontype)
). Couldn't that be used?

In any case, adding a whole new public API for this seems excessive.

@mkitti
Copy link
Contributor Author

mkitti commented Aug 2, 2021

That's the first I've heard of Experimental.register_error_hint. Sounds like that could address #17062 in general as well.

My inclination then is to go back to InteractiveUtils and register an error hint from there since having the help message displayed only makes sense when interactive.

@vtjnash
Copy link
Sponsor Member

vtjnash commented Aug 2, 2021

The hook is also already registered for REPL and can be extended to add this text for handling "help". See #40545 :)

@KristofferC
Copy link
Sponsor Member

Just as a remark, Python seems to implement it in a similar way to #41749

>>> def f():
...     return help
... 
>>> x = f()
>>> type(x)
<class 'site._Helper'>
>>> x
Type help() for interactive help, or help(object) for help about object.

@mkitti
Copy link
Contributor Author

mkitti commented Aug 2, 2021

Do we still want to show the error in this specific case of help? The implementation here and in #41749 preempts the error from even showing.

The suggestion hook seems to display after showing the error.

@mkitti mkitti changed the title Display help message upon UndefVarError(:help), implement basic REPL.error_display_handler Display help message upon UndefVarError(:help) using REPL.REPLCompletitions.UndefVarError_hint Aug 2, 2021
@mkitti
Copy link
Contributor Author

mkitti commented Aug 2, 2021

I've force pushed a new commit that implements a much simpler change in REPL.REPLCompletitions.UndefVarError_hint. ERROR: UndefVarError: help not defined is now displayed which was not shown in the prior iteration or in the #41749 implementation.

We may want to add a mechanism to suppress the error message in the future, but that is for another pull request.

@mkitti
Copy link
Contributor Author

mkitti commented Aug 3, 2021

Looks like all the tests pass this time.

@mkitti
Copy link
Contributor Author

mkitti commented Aug 12, 2021

Perhaps I spoke too soon. I'm not sure what's happening with buildbot/package_freebsd64 build, but I'm pretty sure it is unrelated.

Any other thoughts or comments in the meantime?

@timholy timholy merged commit 8cad32b into JuliaLang:master Aug 14, 2021
@timholy
Copy link
Sponsor Member

timholy commented Aug 14, 2021

Thanks @mkitti, this will be a very nice usability enhancement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants