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

gh-110944: Make pdb completion work for alias and convenience vars #110945

Merged
merged 7 commits into from
Nov 14, 2023

Conversation

gaogaotiantian
Copy link
Member

@gaogaotiantian gaogaotiantian commented Oct 16, 2023

$ was removed from the delimiters as it was used for convenience variables.

@gaogaotiantian gaogaotiantian changed the title gh:110944: Make pdb completion work for alias and convenience vars gh-110944: Make pdb completion work for alias and convenience vars Oct 16, 2023
@@ -232,7 +232,7 @@ def __init__(self, completekey='tab', stdin=None, stdout=None, skip=None,
try:
import readline
# remove some common file name delimiters
readline.set_completer_delims(' \t\n`@#$%^&*()=+[{]}\\|;:\'",<>?')
readline.set_completer_delims(' \t\n`@#%^&*()=+[{]}\\|;:\'",<>?')
Copy link
Member

Choose a reason for hiding this comment

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

There are no tests in this PR.

What could this change break?

Copy link
Member Author

@gaogaotiantian gaogaotiantian Oct 16, 2023

Choose a reason for hiding this comment

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

There's no test for completion, presumably because it's not easy to test. It would change the behavior when the user tries to do a complete (hit <tab> in most cases) and there's a $ in the line. In that case, $ would be not considered as a delimiter (the text to be completed would include $). I can't think of any real cases where this matters. Actually, I can't think of a case where the user uses $ in their pdb commands (other than using convenience variable of course).

@@ -670,6 +670,19 @@ def set_convenience_variable(self, frame, name, value):
# Generic completion functions. Individual complete_foo methods can be
# assigned below to one of these functions.

def completenames(self, text, line, begidx, endidx):
Copy link
Member

Choose a reason for hiding this comment

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

Is this used anywhere?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is overwritting the completenames method defined in cmd.Cmd, which is called when the user tries to complete the command.

Pdb class has some implicit inheritance from cmd.Cmd class to achieve customized behaviors. I can add some comments here if it helps.

Copy link
Member

Choose a reason for hiding this comment

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

I think adding a test that covers this would be better.

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think you can (easily) set up a readline test to really trigger the "complete" feature of readline. Even test_cmd does not test against complete features for cmd.Cmd. I can add some unitttest just to test this method (feeding mock arguments to the function), but a real functional test involving readline would be a large amount of work - and we should probably do that for cmd first if we consider adding it.

@encukou
Copy link
Member

encukou commented Nov 3, 2023

Would you be willing to add that test? It would make it much easier to review this change.

There is an existing pty-based helper in test_readline that could be moved to a shared test.support.pty_helper.py file for reuse in pdb tests: https://github.com/python/cpython/blob/main/Lib/test/test_readline.py#L307

@gaogaotiantian
Copy link
Member Author

gaogaotiantian commented Nov 3, 2023

Would you be willing to add that test? It would make it much easier to review this change.

There is an existing pty-based helper in test_readline that could be moved to a shared test.support.pty_helper.py file for reuse in pdb tests: https://github.com/python/cpython/blob/main/Lib/test/test_readline.py#L307

I put the helper into a new file as you said, then added some completion tests for pdb. It's not "complete", but it's at least something, and it tests the changes I made for this PR. I'll see if there are more interesting cases now that we have the structure.

Also, cmd obviously does not work with libedit, which takes a significant market on MacOS. For now, I disabled the test with libedit. We should deal with it after we fix #102130

@gaogaotiantian
Copy link
Member Author

Hi @iritkatriel , tests were added for both pdb and cmd. After we merge this, we can do the cmd libedit support. (Or we can do it vice versa, but writing test for the other PR is difficult).

This PR:

  • Disables a test on libedit
  • Introduces the helper for pty

The other PR:

  • Supports libedit for cmd
  • Needs the pty helper to write tests

So either

  • This PR -> the other PR with tests -> Remove the disable of this PR, or
  • The other PR without tests -> This PR with removed disable check -> tests to the other PR.

@iritkatriel
Copy link
Member

I'm not familiar with libedit/pty. I think @serhiy-storchaka might be?

Copy link
Member

@encukou encukou left a comment

Choose a reason for hiding this comment

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

Thank you. I'm not very familiar with libedit/pty either, but this looks reasonable to me. If we don't find a better expert, let's merge it!

It would be best if you could split this PR into one that adds the test_basic_completion test, and the one that adds the functionality (and the test for it).
The basic test could then be more easily backported to maintenance versions of Python. It's OK to link both PRs to the same issue.

I also have a few nitpicks below.

(If you don't want to take on the extra work, let me know -- I can take over)

Lib/pdb.py Outdated Show resolved Hide resolved
Lib/test/test_pdb.py Outdated Show resolved Hide resolved
Lib/test/test_pdb.py Outdated Show resolved Hide resolved
@gaogaotiantian
Copy link
Member Author

@encukou sure I cherry-picked the pty-helper piece and the basic test to another PR #111826. Let's finish that PR and circle back to this one.

encukou and others added 2 commits November 13, 2023 11:42
@gaogaotiantian
Copy link
Member Author

@encukou I've applied the suggestions on the code left :) Let me know if there's anything missing from the PR.

@encukou
Copy link
Member

encukou commented Nov 14, 2023

Looks good, thank you!

@encukou encukou merged commit f44d6ff into python:main Nov 14, 2023
22 checks passed
@gaogaotiantian gaogaotiantian deleted the pdb-complete branch November 15, 2023 01:53
aisk pushed a commit to aisk/cpython that referenced this pull request Feb 11, 2024
Glyphack pushed a commit to Glyphack/cpython that referenced this pull request Sep 2, 2024
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.

3 participants