mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Merge pull request #9064 from tk0miya/refactor_type_annotation
refactor: Add Optional to type annotations
This commit is contained in:
commit
3ad1e5e7d1
@ -526,8 +526,7 @@ class Sphinx:
|
|||||||
``'env'``) to a string. However, booleans are still accepted and
|
``'env'``) to a string. However, booleans are still accepted and
|
||||||
converted internally.
|
converted internally.
|
||||||
"""
|
"""
|
||||||
logger.debug('[app] adding config value: %r',
|
logger.debug('[app] adding config value: %r', (name, default, rebuild, types))
|
||||||
(name, default, rebuild) + ((types,) if types else ()))
|
|
||||||
if rebuild in (False, True):
|
if rebuild in (False, True):
|
||||||
rebuild = 'env' if rebuild else ''
|
rebuild = 'env' if rebuild else ''
|
||||||
self.config.add(name, default, rebuild, types)
|
self.config.add(name, default, rebuild, types)
|
||||||
|
@ -270,7 +270,7 @@ class EpubBuilder(StandaloneHTMLBuilder):
|
|||||||
"""
|
"""
|
||||||
def update_node_id(node: Element) -> None:
|
def update_node_id(node: Element) -> None:
|
||||||
"""Update IDs of given *node*."""
|
"""Update IDs of given *node*."""
|
||||||
new_ids = []
|
new_ids: List[str] = []
|
||||||
for node_id in node['ids']:
|
for node_id in node['ids']:
|
||||||
new_id = self.fix_fragment('', node_id)
|
new_id = self.fix_fragment('', node_id)
|
||||||
if new_id not in new_ids:
|
if new_id not in new_ids:
|
||||||
|
@ -407,7 +407,7 @@ def generate_autosummary_docs(sources: List[str], output_dir: str = None,
|
|||||||
logger.warning(__('[autosummary] failed to import %r: %s') % (entry.name, e))
|
logger.warning(__('[autosummary] failed to import %r: %s') % (entry.name, e))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
context = {}
|
context: Dict[str, Any] = {}
|
||||||
if app:
|
if app:
|
||||||
context.update(app.config.autosummary_context)
|
context.update(app.config.autosummary_context)
|
||||||
|
|
||||||
|
@ -12,7 +12,8 @@ import traceback
|
|||||||
import warnings
|
import warnings
|
||||||
from importlib import import_module
|
from importlib import import_module
|
||||||
from types import MethodType
|
from types import MethodType
|
||||||
from typing import TYPE_CHECKING, Any, Callable, Dict, Iterator, List, Tuple, Type, Union
|
from typing import (TYPE_CHECKING, Any, Callable, Dict, Iterator, List, Optional, Tuple, Type,
|
||||||
|
Union)
|
||||||
|
|
||||||
from docutils import nodes
|
from docutils import nodes
|
||||||
from docutils.io import Input
|
from docutils.io import Input
|
||||||
@ -286,7 +287,7 @@ class SphinxComponentRegistry:
|
|||||||
parser.set_application(app)
|
parser.set_application(app)
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
def get_source_input(self, filetype: str) -> Type[Input]:
|
def get_source_input(self, filetype: str) -> Optional[Type[Input]]:
|
||||||
warnings.warn('SphinxComponentRegistry.get_source_input() is deprecated.',
|
warnings.warn('SphinxComponentRegistry.get_source_input() is deprecated.',
|
||||||
RemovedInSphinx60Warning)
|
RemovedInSphinx60Warning)
|
||||||
|
|
||||||
|
@ -749,7 +749,7 @@ def getdoc(obj: Any, attrgetter: Callable = safe_getattr,
|
|||||||
elif doc is None and allow_inherited:
|
elif doc is None and allow_inherited:
|
||||||
doc = inspect.getdoc(obj)
|
doc = inspect.getdoc(obj)
|
||||||
|
|
||||||
if doc is None and cls:
|
if doc is None and cls and name:
|
||||||
# inspect.getdoc() does not support some kind of inherited and decorated methods.
|
# inspect.getdoc() does not support some kind of inherited and decorated methods.
|
||||||
# This tries to obtain the docstring from super classes.
|
# This tries to obtain the docstring from super classes.
|
||||||
for basecls in getattr(cls, '__mro__', []):
|
for basecls in getattr(cls, '__mro__', []):
|
||||||
|
Loading…
Reference in New Issue
Block a user