-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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
In documentation same-named attributes erroneously link to built-in names #90744
Comments
https://docs.python.org/3.11/library/enum.html#module-contents contains: In above, property() is links to: |
Changing the markup to this should fix the link without changing the text: :func:`~enum.property` Would you like to turn this into a pull request? |
|
What does the tilde (~) do? |
:func:`~enum.property` means that the visible text on the webpage will be "property", but the link will be to enum.property rather than builtins.property. |
The ~ always only uses the final part of the name for the display text, e.g. |
(First time contributor here seeking guidance) I see that this problem of automatically linking to the unintended page has occurred in other parts of the docs and has been handled in another way - In Doc/library/functions.rst, local targets are used with replacement texts- unintended linking code- :func:`dict` Would this be the preferred way of solving this? I tried this change and it achieves the correct linking for me |
Using a substitution is necessary when we need code markup and a link. For this bug, the simple ~ markup will be enough. |
The same problem exists for any attribute that has the same name as a builtin, see for example https://docs.python.org/3/library/sys.html#sys.float_info |
I looked through the sys.float_info docs and I guess that you are referring to the max and min attributes of sys.float_info that are linking to the built-in max() and min() functions? In that case as there is no documentation for the max and min attributes of sys.float_info, should they not link to anything? |
Yes, I was referring to these two attributes. |
It took me some time to figure out how to prevent the creation of a reference/hyperlink using the ! prefix. I've made the change to remove the references to the max and min attributes of sys.float_info and pushed. How do I find other instances of this problem? Is there a systematic way to look for such references? |
You could write a script that goes something like this, iterating over all the docs RST files:
That would catch the enum.property case, but not the float_info one Éric noticed, because sys.rst doesn't define `max` at all. To catch that one, you could look at the link role: sys.rst links to it with :const:`max`, but functions.rst defines it as `.. function:: max`. Mismatches like that could be another clue that something is wrong (but there are some legitimate reasons why the roles won't match perfectly, like "decorator" in the definition vs. "func" in the link). |
Can someone guide me on why I'm getting a no-new-line at end of file error for the NEWS entry when I didnt change this file in the last commit and it passed the Azure checks earlier Error: [1] ../Misc/NEWS.d/next/Documentation/2022-02-08-15-38-16.bpo-46586.6qVFVL.rst:0: No newline at end of file (no-newline-at-end-of-file). Do I need to manually add the new line? |
An updated reST linting check was added between the time you created the PR and your last update. As Jelle noted on the PR, there doesn't need to be a NEWS entry for this anyway. We might have an issue there if sphinx-lint is going to have an issue with no trailing newline and blurb-it isn't going to add a trailing newline, though. (+mdk) |
Thinking about it again: The issue is that these tables (for sys.float_info and other named tuples / structseqs) use the const role, which is not meant to identify attributes but to link to them (similar to func, mod, data, etc). In other words we are fixing an issue that a wrong target is used, but we should not be linking for a target at all, this is the target. So if we can’t use the equivalent of directives function, module, etc (that define the targets of func, mod, etc), then maybe they should be just ``name``, not :role:`name`. |
Thanks Jelle for the cool idea of the script to look for more instances of this problem. I've been working on this script and am still refining it, but one of the candidates that my program returned is in zipfile.rst - https://docs.python.org/3.11/library/zipfile.html?highlight=zipfile#zipfile.ZipFile.open Changed in version 3.6: open() can now be used to write files into the archive with the mode='w' option. Here the first instance of open() points to the builtins function rather than ZipFile.open(), whereas the second instance points to ZipFile.open(). Seems like a true positive to me, what do you think? |
Also this one?- Arguments, return values and exceptions raised are the same as those of urlopen() (which simply calls the open() method on the currently installed global OpenerDirector). open() points to the builtins function but the markup used is :meth:`open` and the logic of the sentence suggests the link was meant to be to OpenerDirector.open() |
Looks like another one - Deprecated since version 3.10: This function is deprecated since input() and FileInput now have encoding and errors parameters. The input() here points to builtins which doesnt have the mentioned parameters |
https://docs.python.org/3.11/library/io.html?highlight=io#text-i-o - The easiest way to create a text stream is with open(), optionally specifying an encoding: https://docs.python.org/3.11/library/io.html?highlight=io#binary-i-o - The easiest way to create a binary stream is with open() with 'b' in the mode string: For both of these cases, the markup for the open() is :meth:`open()` but it links to the builtins open(), which I see is an alias of io.open() so maybe it doesn't matter? |
The PR is ready for review. |
Co-authored-by: Hugo van Kemenade <[email protected]>
) Co-authored-by: Hugo van Kemenade <[email protected]>
) Co-authored-by: Hugo van Kemenade <[email protected]>
* main: (67 commits) pythongh-99108: Add missing md5/sha1 defines to Modules/Setup (python#102308) pythongh-100227: Move _str_replace_inf to PyInterpreterState (pythongh-102333) pythongh-100227: Move the dtoa State to PyInterpreterState (pythongh-102331) pythonGH-102305: Expand some macros in generated_cases.c.h (python#102309) Migrate to new PSF mailgun account (python#102284) pythongh-102192: Replace PyErr_Fetch/Restore etc by more efficient alternatives (in Python/) (python#102193) pythonGH-90744: Fix erroneous doc links in the sys module (python#101319) pythongh-87092: Make jump target label equal to the offset of the target in the instructions sequence (python#102093) pythongh-101101: Unstable C API tier (PEP 689) (pythonGH-101102) IDLE: Simplify DynOptionsMenu __init__code (python#101371) pythongh-101561: Add typing.override decorator (python#101564) pythongh-101825: Clarify that as_integer_ratio() output is always normalized (python#101843) pythongh-101773: Optimize creation of Fractions in private methods (python#101780) pythongh-102251: Updates to test_imp Toward Fixing Some Refleaks (pythongh-102254) pythongh-102296 Document that inspect.Parameter kinds support ordering (pythonGH-102297) pythongh-102250: Fix double-decref in COMPARE_AND_BRANCH error case (pythonGH-102287) pythongh-101100: Fix sphinx warnings in `types` module (python#102274) pythongh-91038: Change default argument value to `False` instead of `0` (python#31621) pythongh-101765: unicodeobject: use Py_XDECREF correctly (python#102283) [doc] Improve grammar/fix missing word (pythonGH-102060) ...
#102321) Co-authored-by: Hugo van Kemenade <[email protected]> Co-authored-by: Brad Wolfe <[email protected]> Co-authored-by: Furkan Onder <[email protected]> Fix erroneous doc links in the sys module (#101319)
#102322) Co-authored-by: Hugo van Kemenade <[email protected]> Co-authored-by: Brad Wolfe <[email protected]> Co-authored-by: Furkan Onder <[email protected]> Fix erroneous doc links in the sys module (#101319)
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
Linked PRs
The text was updated successfully, but these errors were encountered: