-
-
Notifications
You must be signed in to change notification settings - Fork 32.6k
gh-137574: Add Support For Special Names in help
#137966
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
base: main
Are you sure you want to change the base?
Conversation
This PR is way too big. Also, don't regenerate |
I think the majority of the diff is from |
I'm on mobile so it's hard to tell (the pydoc data diff doesn't even render). I'll look at the PR substantively over the week though. |
It is definitely true that most of the diff here is coming from I had regenerated |
I think that's fine, we want to keep the diff down as much as possible. Someone (presumably Hugo) will regenerate it when it's time to do 3.15a1. |
OK, sounds fair. Some of my new tests won't pass without the additions to |
Hm, I'm not sure then. We should look into previous PRs to see what they did. |
Taking a quick look at I'll leave things here for now (the changes to |
Following on from #137574, this is an attempt to provide better help for special names from the built-in
help
function.The original question was about
help('__name__')
andhelp('__dict__')
, which suggested help for thestr
anddict
built-in types, respectively, instead of reporting an error that no help was available for those topics. I also took this a step further, adding help for the special method names described on the 'Data Model' page of the language reference, as well as'__name__'
and'__main__'
.Here's a quick summary of the changes I made:
When requesting help on a name
'__x__'
, only report on the result ofgetattr(builtins, '__x__')
if it is a type or a built-in function, preventing the confusion described above.Added help for
__name__
,__main__
, and the special method names as help topics.Added
"specialnames"
as a new top-level category, and included it as a suggestion if we were looking up a name starting and ending with__
.Added a reference to the online Python docs in the message when a help topic isn't found, and slightly changed the wording of that message, hoping not to imply that things that don't have associated
help
topics aren't documented at all.If any of these changes is a bridge too far, I can roll them back. Two other concerns, as well:
The code style of
pydoc.py
doesn't match whatruff
would output, in a number of places. I opted to mimic the existing code's style rather than using input thatruff
would be happy with; I can reformat, though, if that would be better.One of the tests I added (which tests that each dunder method shows up in its
help
output) is quite slow. I could rework that so that it only tests a few names if that test being slow is a problem.help()
#137574📚 Documentation preview 📚: https://cpython-previews--137966.org.readthedocs.build/