Merge pull request #7254 from tk0miya/6895_suppress_builtin_nitpicky_warning

Fix #6895: py domain: Do not emit nitpicky warnings for built-in types
This commit is contained in:
Takeshi KOMIYA 2020-03-07 02:12:50 +09:00 committed by GitHub
commit 7652052bf8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 0 deletions

View File

@ -62,6 +62,7 @@ Features added
* #3106: domain: Register hyperlink target for index page automatically * #3106: domain: Register hyperlink target for index page automatically
* #6558: std domain: emit a warning for duplicated generic objects * #6558: std domain: emit a warning for duplicated generic objects
* #6830: py domain: Add new event: :event:`object-description-transform` * #6830: py domain: Add new event: :event:`object-description-transform`
* #6895: py domain: Do not emit nitpicky warnings for built-in types
* py domain: Support lambda functions in function signature * py domain: Support lambda functions in function signature
* Support priority of event handlers. For more detail, see * Support priority of event handlers. For more detail, see
:py:meth:`.Sphinx.connect()` :py:meth:`.Sphinx.connect()`

View File

@ -8,7 +8,10 @@
:license: BSD, see LICENSE for details. :license: BSD, see LICENSE for details.
""" """
import builtins
import inspect
import re import re
import typing
import warnings import warnings
from inspect import Parameter from inspect import Parameter
from typing import Any, Dict, Iterable, Iterator, List, Tuple from typing import Any, Dict, Iterable, Iterator, List, Tuple
@ -1195,11 +1198,37 @@ class PythonDomain(Domain):
return '.'.join(filter(None, [modname, clsname, target])) return '.'.join(filter(None, [modname, clsname, target]))
def builtin_resolver(app: Sphinx, env: BuildEnvironment,
node: pending_xref, contnode: Element) -> Element:
"""Do not emit nitpicky warnings for built-in types."""
def istyping(s: str) -> bool:
if s.startswith('typing.'):
s = s.split('.', 1)[1]
return s in typing.__all__ # type: ignore
if node.get('refdomain') != 'py':
return None
elif node.get('reftype') == 'obj' and node.get('reftarget') == 'None':
return contnode
elif node.get('reftype') in ('class', 'exc'):
reftarget = node.get('reftarget')
if inspect.isclass(getattr(builtins, reftarget, None)):
# built-in class
return contnode
elif istyping(reftarget):
# typing class
return contnode
return None
def setup(app: Sphinx) -> Dict[str, Any]: def setup(app: Sphinx) -> Dict[str, Any]:
app.setup_extension('sphinx.directives') app.setup_extension('sphinx.directives')
app.add_domain(PythonDomain) app.add_domain(PythonDomain)
app.connect('object-description-transform', filter_meta_fields) app.connect('object-description-transform', filter_meta_fields)
app.connect('missing-reference', builtin_resolver, priority=900)
return { return {
'version': 'builtin', 'version': 'builtin',