mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Fix mypy violations
This commit is contained in:
parent
b2837eee0c
commit
fe07365a8c
@ -33,7 +33,6 @@ from sphinx.deprecation import RemovedInSphinx20Warning
|
||||
from sphinx.environment import BuildEnvironment
|
||||
from sphinx.events import EventManager
|
||||
from sphinx.extension import verify_required_extensions
|
||||
from sphinx.io import SphinxStandaloneReader
|
||||
from sphinx.locale import __
|
||||
from sphinx.registry import SphinxComponentRegistry
|
||||
from sphinx.util import pycompat # noqa: F401
|
||||
@ -54,7 +53,9 @@ if False:
|
||||
from sphinx.domains import Domain, Index # NOQA
|
||||
from sphinx.environment.collectors import EnvironmentCollector # NOQA
|
||||
from sphinx.extension import Extension # NOQA
|
||||
from sphinx.roles import XRefRole # NOQA
|
||||
from sphinx.theming import Theme # NOQA
|
||||
from sphinx.util.typing import RoleFunction # NOQA
|
||||
|
||||
builtin_extensions = (
|
||||
'sphinx.builders.applehelp',
|
||||
@ -563,7 +564,7 @@ class Sphinx(object):
|
||||
has_content, argument_spec, **option_spec)
|
||||
|
||||
def add_role_to_domain(self, domain, name, role):
|
||||
# type: (unicode, unicode, Any) -> None
|
||||
# type: (unicode, unicode, Union[RoleFunction, XRefRole]) -> None
|
||||
self.registry.add_role_to_domain(domain, name, role)
|
||||
|
||||
def add_index_to_domain(self, domain, index):
|
||||
|
@ -141,7 +141,7 @@ class Domain(object):
|
||||
#: domain label: longer, more descriptive (used in messages)
|
||||
label = ''
|
||||
#: type (usually directive) name -> ObjType instance
|
||||
object_types = {} # type: Dict[unicode, Any]
|
||||
object_types = {} # type: Dict[unicode, ObjType]
|
||||
#: directive name -> directive class
|
||||
directives = {} # type: Dict[unicode, Any]
|
||||
#: role name -> role callable
|
||||
|
@ -86,7 +86,7 @@ class SphinxStandaloneReader(SphinxBaseReader):
|
||||
def __init__(self, app, *args, **kwargs):
|
||||
# type: (Sphinx, Any, Any) -> None
|
||||
self.transforms = self.transforms + app.registry.get_transforms()
|
||||
SphinxBaseReader.__init__(self, *args, **kwargs)
|
||||
SphinxBaseReader.__init__(self, *args, **kwargs) # type: ignore
|
||||
|
||||
|
||||
class SphinxI18nReader(SphinxBaseReader):
|
||||
|
@ -29,7 +29,7 @@ from sphinx.util.docutils import directive_helper
|
||||
|
||||
if False:
|
||||
# For type annotation
|
||||
from typing import Any, Callable, Dict, Iterator, List, Type # NOQA
|
||||
from typing import Any, Callable, Dict, Iterator, List, Type, Union # NOQA
|
||||
from docutils import nodes # NOQA
|
||||
from docutils.io import Input # NOQA
|
||||
from docutils.parsers import Parser # NOQA
|
||||
@ -38,6 +38,7 @@ if False:
|
||||
from sphinx.builders import Builder # NOQA
|
||||
from sphinx.domains import Domain, Index # NOQA
|
||||
from sphinx.environment import BuildEnvironment # NOQA
|
||||
from sphinx.util.typing import RoleFunction # NOQA
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@ -53,9 +54,9 @@ class SphinxComponentRegistry(object):
|
||||
self.builders = {} # type: Dict[unicode, Type[Builder]]
|
||||
self.domains = {} # type: Dict[unicode, Type[Domain]]
|
||||
self.domain_directives = {} # type: Dict[unicode, Dict[unicode, Any]]
|
||||
self.domain_indices = {} # type: Dict[unicode, List[Index]]
|
||||
self.domain_indices = {} # type: Dict[unicode, List[Type[Index]]]
|
||||
self.domain_object_types = {} # type: Dict[unicode, Dict[unicode, ObjType]]
|
||||
self.domain_roles = {} # type: Dict[unicode, Dict[unicode, Any]]
|
||||
self.domain_roles = {} # type: Dict[unicode, Dict[unicode, Union[RoleFunction, XRefRole]]] # NOQA
|
||||
self.post_transforms = [] # type: List[Type[Transform]]
|
||||
self.source_parsers = {} # type: Dict[unicode, Parser]
|
||||
self.source_inputs = {} # type: Dict[unicode, Input]
|
||||
@ -139,7 +140,7 @@ class SphinxComponentRegistry(object):
|
||||
directives[name] = directive_helper(obj, has_content, argument_spec, **option_spec)
|
||||
|
||||
def add_role_to_domain(self, domain, name, role):
|
||||
# type: (unicode, unicode, Any) -> None
|
||||
# type: (unicode, unicode, Union[RoleFunction, XRefRole]) -> None
|
||||
logger.debug('[app] adding role to domain: %r', (domain, name, role))
|
||||
if domain not in self.domains:
|
||||
raise ExtensionError(__('domain %s not yet registered') % domain)
|
||||
@ -186,8 +187,8 @@ class SphinxComponentRegistry(object):
|
||||
(Target, object),
|
||||
{'indextemplate': indextemplate})
|
||||
|
||||
self.add_directive_to_domain('std', directive)
|
||||
self.add_role_to_domain('std', XRefRole(innernodeclass=ref_nodeclass))
|
||||
self.add_directive_to_domain('std', directivename, directive)
|
||||
self.add_role_to_domain('std', rolename, XRefRole(innernodeclass=ref_nodeclass))
|
||||
|
||||
object_types = self.domain_object_types.setdefault('std', {})
|
||||
object_types[directivename] = ObjType(objname or directivename, rolename)
|
||||
|
Loading…
Reference in New Issue
Block a user