mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
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:
commit
7652052bf8
1
CHANGES
1
CHANGES
@ -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()`
|
||||||
|
@ -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',
|
||||||
|
Loading…
Reference in New Issue
Block a user