Repository navigation
gh-137574: Add Support For Special Names in help - #137966
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. |
There was a problem hiding this comment.
Please revert this change, it will be done as part of the release.
There was a problem hiding this comment.
The issue is that those changes are necessary for this PR to work, since some of the new topics added to help require topics that aren't currently in there and so would be broken / hard to test. I can revert if the idea is that reviewers will re-generate that file on their own for testing, but just wanted to flag that the PR won't work as expected without it before actually rolling it back.
There was a problem hiding this comment.
Regeneration at release is the standard process (it's automatically done by release-tools), it makes this easier to review IMO.
There was a problem hiding this comment.
Right, but not regenerating makes this very difficult to test locally. How does this make it more difficult to review? Just ignore the regenerated file.
There was a problem hiding this comment.
Since we don't verify it in the CI, it's another file that needs manual verification.
There was a problem hiding this comment.
Sure, but manually verifying a generated file is much easier (and less harmful if we mess up) than letting a feature hit main and not work until release. Keep in mind that removing the generated file will also mean we have to remove a bunch of test coverage from this PR. We would, in essence, be trading the guarantee that the generated file is correct for the guarantee that the feature works correctly.
I'm inclined to cite "practicality beats purity" here. Yes, regenerating is a very minor breach of process, but I think reviewing this PR is much more difficult without the regenerated file, not vice versa.
There was a problem hiding this comment.
My concern is more around security than correctness here (and not specific to this PR or its author). Since these generated files aren't verified in CI, changes to them in PRs introduce another potential attack surface that reviewers need to manually inspect.
Another downside of regenerating these files outside of releases is the potential for merge conflicts, though I don't think that's much of an issue in the case of pydoc.
That said, I understand the testing concerns, so if you'd like to keep the generated file in and verify the changes, I won't block on it.
There was a problem hiding this comment.
Yeah, I'm not saying we should make this a common policy; I'm just arguing that we should make an exception for this PR. I'll make sure it's correct before landing this.
Or, we could verify pydoc_data as part of the "Check if generated files are up to date" CI check, assuming the generation is pretty fast.
Documentation build overview
179 files changed ·
|
|
Thanks for the quick and thorough review, @ZeroIntensity! I added a what's new entry and I believe I fixed the merge conflicts. I responded to some of your specific comments/requests inline above, and of course, happy for more input if you have it. |
|
Oops, sorry, some of these changes broke some tests. Will ping again when that's resolved. Sorry for the noise. |
|
The failing test was caused by having two |
|
We do our best to avoid removing Sphinx labels when possible (notice the failing CI job). |
I understand that, and I agree with the rationale of not breaking links, but I would argue that the addition of that new duplicate reference was a bug, since it is the thing breaking existing links (and it isn't referenced anywhere else in the docs as far as I can see), whereas the old The new duplicate label looks like it was added in bd31583, per |
|
Would you mind opening a separate issue and PR for that? Feel free to tag me for a review. |
|
Sorry for the delay. This looks pretty good overall now. I'll try to finish up my review tomorrow, but if not, I'll get to it sometime this upcoming week during the core sprint. |
| if ( | ||
| _is_dunder_name(path) | ||
| and not isinstance(object, (type, type(__import__))) | ||
| and path not in SKIP_DUNDER_HELP | ||
| ): |
There was a problem hiding this comment.
Rather than an allowlist of things to skip, we shouldn't skip any module that is successfully imported. There are some legitimate names for modules that are dunders, such as __about__ or __init__. The rest of this PR looks good otherwise.
There was a problem hiding this comment.
Thanks again for reviewing, and sorry for being slow here. I'll be able to get back to this sometime this weekend.
There was a problem hiding this comment.
Sorry again that it took a while for me to get back to this.
I just pushed a change that handles modules like __future__ a bit more elegantly. That said, when poking around, I'm noticing that there are still a bunch of dunder methods (__abs__, __enter__, etc.) that don't currently have entries here. Is it worth adding those?
There are also other things that could probably use specialized help (like, for example, __file__).
If you think those are worth adding here, I can have a go at adding them sometime this week.
There was a problem hiding this comment.
I think they're worth adding, but that can happen in a follow-up. This PR is large enough as it is :)
ZeroIntensity
left a comment
There was a problem hiding this comment.
LGTM! Let's build on this.
Following on from #137574, this is an attempt to provide better help for special names from the built-in
helpfunction.The original question was about
help('__name__')andhelp('__dict__'), which suggested help for thestranddictbuilt-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
helptopics 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.pydoesn't match whatruffwould output, in a number of places. I opted to mimic the existing code's style rather than using input thatruffwould 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
helpoutput) 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/