Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32k
bpo-37030: hide undocumented commands in cmd module#13536
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Conversation
…enamesA flag, defaulting to false. If true, :meth:`do_help` and :meth:`completenames`won't include undocumented commands (that is, there are do_*() methods withoutcorresponding help_*() methods).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Left comment for doc and test. But in general would like to hear from a core dev on this.
return [a[3:] for a in self.get_names() if a.startswith(dotext)] | ||
names = self.get_names() | ||
commands = [a[3:] for a in names if a.startswith(dotext)] | ||
if self.hide_undoc: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Please add a test similar to
Line 55 inf1e17e9
>>> mycmd.completenames("a") |
mycmd.hide_undoc = True
and make sure "shell" is not returned by thecompletenames
function for "s". Set itmycmd.hide_undoc = False
for rest of the tests to make sure to make sure other tests are not affected.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
ok, figured it out and made commit.
Uh oh!
There was an error while loading.Please reload this page.
I have made the requested changes; please review again |
bedevere-bot commentedJul 4, 2019
Thanks for making the requested changes! : please review the changes made to this pull request. |
The current behavior of the cmd module is to return the string 'EOF'when the program receives an EOF (e.g. when you press ctrl + d,or when the end of a file is reached). When you're writing some kind ofREPL, you often want to exit when when you get an EOF (for example,python's REPL exits when you press ctrl + d). The way toachieve that functionality here is to create a functioncalled `do_EOF` in your subclass of `cmd.Cmd`, and call `exit()`If you want some other behavior when you get an EOF, you can putthat in `do_EOF` instead.This is problematic for two main reasons:1. `EOF` shows up as an undocumented command when you type `help`. It'snot that big of a deal, but it's definitely not ideal (and perhapsconfusing).2. If you type `EOF` into the terminal, it will call your `do_EOF`function. If your `do_EOF` function exits, typing `do_EOF` will exit theprogram. Seems rather silly.I propose the cmd class NOT catch the EOFError. That will eliminate bothof the above problems. I realize this could be an issue with backwardscompatibility and such, but I don't think it would require muchadjustment (maybe a couple lines).See alsohttps://bugs.python.org/issue13214 andpython#13536
Why would we want to encourage undocumented commands? This seems like an anti-pattern to me. |
The reason was to have some secret functions for professional users or to have some try out functions that normal users would not start calling support about immediately. On the other had it bothered me that they are in the list to ask help for, while there is no help available for these anyway. |
python-cla-botbot commentedApr 18, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
A flag, defaulting to false. If true, :meth:
do_help
and :meth:completenames
won't include undocumented commands (that is, there are do_() methods without
corresponding help_() methods).
https://bugs.python.org/issue37030