Python Console: Preserve the result of the last executed command (#9782)#9783
Merged
Conversation
LeonarddeR
approved these changes
Jun 21, 2019
LeonarddeR
left a comment
Collaborator
There was a problem hiding this comment.
I really like this proposal, however, I think it needs to be documented in the developer guide that in most cases, _ contains the last result on the python console instead of the gettext function and that it could always be accessed by explicitly delling _ or using builtin._. I've already verified that this will work in the Python 3 version of NVDA as well, as long as builtin is renamed to builtins
…ccess#9782) Update Developer Guide
michaelDCurran
approved these changes
Jun 25, 2019
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Link to issue number:
Fixes #9782
Summary of the issue:
The NVDA Python Console implementation prevents clobbering of the gettext "_" built-in but at the same time prevents the user from taking advantage of the standard sys.displayhook saving the last returned value under that same name.
Description of how this pull request fixes the issue:
Save the last execution result in the global namespace rather than in
__builtins__.Gettext is thus not affected.
Testing performed:
Known issues with pull request:
Unlike on the standard Python Console where the "" special variable is stored in builtins, a variable named "" in the global namespace will be overridden every time a command is executed.
An exception is made for the gettext function. That is, if it is explicitly promoted to the global namespace by executing
_ = _it won't get overridden on subsequent commands execution until explicitly deleted bydel _.If this is to be considered a problem, a little more intrusive implementation could extend the namespace dictionary to specially handle "_" and preserve any manually defined global with that name.
Furthermore,
Noneis the only special value in the standardsys.displayhook, as it never overrides the "_" built-in. This PR treats the gettext function in the same way and thus does not override the last result if the executed command returns eitherNoneor the gettext function.If this is to be considered a problem, I guess a custom display hook could do the trick, but I doubt it would be worth the effort.
Change log entry:
Python Console: The global variable "_" now stores the result of the last executed command.