-
-
Notifications
You must be signed in to change notification settings - Fork 32.9k
Fixed #36570 -- Removed unnecessary :py domain from documentation roles. #19772
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
Conversation
There are quite a few more, e.g. |
e002115
to
4c6da46
Compare
@sarahboyce Thank you! I’ve updated all the values you pointed out. It would be even more helpful if there were a hook to catch any :py: parts early on. Do you think it might be possible to catch these through something like a pre-commit hook or during CI? |
fabd252
to
3ef5154
Compare
How about something like this? diff --git a/docs/lint.py b/docs/lint.py
index cb129997b2..5c8c8af749 100644
--- a/docs/lint.py
+++ b/docs/lint.py
@@ -5,12 +5,14 @@ from os.path import abspath, dirname, splitext
from unittest import mock
from sphinxlint.checkers import (
+ _ROLE_BODY,
_is_long_interpreted_text,
_is_very_long_string_literal,
_starts_with_anonymous_hyperlink,
_starts_with_directive_or_hyperlink,
)
from sphinxlint.checkers import checker as sphinxlint_checker
+from sphinxlint.rst import SIMPLENAME
from sphinxlint.sphinxlint import check_text
from sphinxlint.utils import PER_FILE_CACHES, hide_non_rst_blocks
@@ -116,6 +118,24 @@ def check_line_too_long_django(file, lines, options=None):
yield lno + 1, f"Line too long ({len(line) - 1}/{options.max_line_length})"
+_PYTHON_DOMAIN = re.compile(f":py:{SIMPLENAME}:`{_ROLE_BODY}`")
+
+
+@sphinxlint_checker(".rst", enabled=False, rst_only=True)
+def check_python_domain_in_roles(file, lines, options=None):
+ """
+ :py: indicates the Python language domain. This means code writen in
+ Python, not Python built-ins in particular.
+
+ Bad: :py:class:`email.message.EmailMessage`
+ Good: :class:`email.message.EmailMessage`
+ """
+ for lno, line in enumerate(lines, start=1):
+ role = _PYTHON_DOMAIN.search(line)
+ if role:
+ yield lno, f":py domain is the default and can be omitted {role.group(0)!r}"
+
+
import sphinxlint # noqa: E402
sphinxlint.check_file = django_check_file |
Hi @smithdc1 — thank you very much. This looks great to me. Would it be okay if I open a PR for this? |
Sure, no problem. I'd suggest adding it as a second commit to this PR though, rather than opening it separately. |
293602a
to
8fb8282
Compare
Signed-off-by: SaJH <wogur981208@gmail.com>
…n in documentation roles.
8fb8282
to
0196980
Compare
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.
Thank you both!
Trac ticket number
ticket-36570
Checklist
main
branch.