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

Make variables command only show user-defined variables #10

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

nfraprado
Copy link
Contributor

Previously the 'variables' command showed all known variables, which
made it hard for the user to find the ones created during the session.
Make the 'variables' command instead only show the variables created by
the user, either through "var=value" or "value 'var' store" during the
current session.

Rename the old variables command to 'variables_all'.

This is being done on top of the 'reverse-reverse-8' branch in order to avoid having to change the test after that branch is merged.

terrycojones and others added 2 commits December 3, 2020 01:32
Previously the 'variables' command showed all known variables, which
made it hard for the user to find the ones created during the session.
Make the 'variables' command instead only show the variables created by
the user, either through "var=value" or "value 'var' store" during the
current session.

Rename the old variables command to 'variables_all'.
@terrycojones
Copy link
Owner

Oh boy.... I only just found this, in my spam folder :-(. Sorry! If I don't respond to things, please feel free to email me at [email protected]

@@ -546,6 +547,7 @@ def _tryEvalExec(self, command, modifiers, count):
value = EngNumber(command)
except decimal.InvalidOperation:
try:
variables_before = set(self._variables.keys())
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need the .keys() here. The dict is being iterated, so you get the keys as a result.

Also, could you use camelCase? I know it's a tiny/silly issue, but I'd prefer to keep the code consistent in that respect. Sorry!

@@ -561,6 +563,13 @@ def _tryEvalExec(self, command, modifiers, count):
'whitespace in a command line?')
raise CalculatorError(*errors)
else:
# If we have new variables, add them to the user variables
# list
variables_after = set(self._variables.keys())
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for .keys().

variables_after = set(self._variables.keys())
new_variables = variables_after.difference(variables_before)
for var in new_variables:
self._userVariables.append(var)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are the user variables a list and not a set? Does that mean that a variable could end up in self._userVariables twice? If you really want it to be a list you can replace these two lines with self._userVariables.extend(new_variables).

@param count: An C{int} count of the number of arguments to pass.
"""
for name, value in sorted(calc._variables.items()):
if name in calc._userVariables:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like self._userVariables should be a set.

@nfraprado
Copy link
Contributor Author

Oh boy.... I only just found this, in my spam folder :-(. Sorry! If I don't respond to things, please feel free to email me at [email protected]

Hey, don't worry about it! I was going to email you after I helped on #9 , to clear the way for this PR, I just didn't find the time for it yet :).

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.

2 participants