Skip to content

bpo-35270: Cmd.complete: use completedefault also with cmd=None #10588

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

blueyed
Copy link
Contributor

@blueyed blueyed commented Nov 17, 2018

Otherwise it will trigger a TypeError ("must be str, not NoneType") below with:

compfunc = getattr(self, 'complete_' + cmd)

The doc for parseline state:

'command' and 'args' may be None if the line couldn't be parsed.

Might need a test of course etc, but maybe one fails already..

https://bugs.python.org/issue35270

TODO:

  • test

Copy link
Contributor

@remilapeyre remilapeyre left a comment

Choose a reason for hiding this comment

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

Thanks for this @blueyed, can you add a test and a Misc/NEWS.d entry? You can either use blurb or https://blurb-it.herokuapp.com/

@blueyed
Copy link
Contributor Author

blueyed commented Feb 8, 2019

Added a test.

@blueyed
Copy link
Contributor Author

blueyed commented Mar 9, 2019

@remilapeyre
Gentle ping.

Otherwise it will trigger a TypeError ("must be str, not NoneType") below with:

    compfunc = getattr(self, 'complete_' + cmd)

The doc for `parseline` states:

> 'command' and 'args' may be None if the line couldn't be parsed.
@blueyed blueyed force-pushed the cmd-complete-None branch from 4bb8624 to 704a33d Compare March 9, 2019 15:13
@blueyed
Copy link
Contributor Author

blueyed commented Mar 9, 2019

Hopefully fixed the test for Windows (skipping with missing readline), and rebased.

Copy link
Contributor

@remilapeyre remilapeyre left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution!

@ghost
Copy link

ghost commented Jan 3, 2024

The following commit authors need to sign the Contributor License Agreement:

Click the button to sign:
CLA not signed

@encukou
Copy link
Member

encukou commented Jan 3, 2024

Hello, and sorry for the delay.
Are you still interested in this PR? You would need to (re)-sign the CLA (click the CI failure).
Also, we can now test readline-related functionality in a PTY, so rather than using mock you could do something like this in CmdTestReadline:

    def test_with_None_from_parseline(self):
        script = textwrap.dedent("""
            import cmd
            class CustomCmd(cmd.Cmd):
                def parseline(self, line):
                    if line.startswith('exit'):
                        return 'exit', '', line
                    return None, None, line

                def completedefault(self, *args):
                    return ['via_completedefault']

                def do_exit(self, args):
                    return True

            CustomCmd().cmdloop()
        """)

        input = b"foo bar\t\nexit\n"

        output = run_pty(script, input)

        self.assertIn(b'via_completedefault', output)

@python-cla-bot
Copy link

python-cla-bot bot commented Apr 6, 2025

The following commit authors need to sign the Contributor License Agreement:

CLA signed

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

Successfully merging this pull request may close these issues.

6 participants