mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Fix sphinx crashes with ImportError on python3.5.1
typing.Type was added since python 3.5.2. So it should be imported only on type checking.
This commit is contained in:
parent
841f1c7e76
commit
5290578256
1
CHANGES
1
CHANGES
@ -25,6 +25,7 @@ Bugs fixed
|
|||||||
* #7479: autodoc: Sphinx builds has been slower since 3.0.0 on mocking
|
* #7479: autodoc: Sphinx builds has been slower since 3.0.0 on mocking
|
||||||
* C++, fix spacing issue in east-const declarations.
|
* C++, fix spacing issue in east-const declarations.
|
||||||
* #7414: LaTeX: Xindy language options were incorrect
|
* #7414: LaTeX: Xindy language options were incorrect
|
||||||
|
* sphinx crashes with ImportError on python3.5.1
|
||||||
|
|
||||||
Testing
|
Testing
|
||||||
--------
|
--------
|
||||||
|
@ -12,7 +12,10 @@ import sys
|
|||||||
import warnings
|
import warnings
|
||||||
from importlib import import_module
|
from importlib import import_module
|
||||||
from typing import Any, Dict
|
from typing import Any, Dict
|
||||||
from typing import Type # for python3.5.1
|
|
||||||
|
if False:
|
||||||
|
# For type annotation
|
||||||
|
from typing import Type # for python3.5.1
|
||||||
|
|
||||||
|
|
||||||
class RemovedInSphinx40Warning(DeprecationWarning):
|
class RemovedInSphinx40Warning(DeprecationWarning):
|
||||||
@ -26,13 +29,13 @@ class RemovedInSphinx50Warning(PendingDeprecationWarning):
|
|||||||
RemovedInNextVersionWarning = RemovedInSphinx40Warning
|
RemovedInNextVersionWarning = RemovedInSphinx40Warning
|
||||||
|
|
||||||
|
|
||||||
def deprecated_alias(modname: str, objects: Dict, warning: Type[Warning]) -> None:
|
def deprecated_alias(modname: str, objects: Dict, warning: "Type[Warning]") -> None:
|
||||||
module = import_module(modname)
|
module = import_module(modname)
|
||||||
sys.modules[modname] = _ModuleWrapper(module, modname, objects, warning) # type: ignore
|
sys.modules[modname] = _ModuleWrapper(module, modname, objects, warning) # type: ignore
|
||||||
|
|
||||||
|
|
||||||
class _ModuleWrapper:
|
class _ModuleWrapper:
|
||||||
def __init__(self, module: Any, modname: str, objects: Dict, warning: Type[Warning]
|
def __init__(self, module: Any, modname: str, objects: Dict, warning: "Type[Warning]"
|
||||||
) -> None:
|
) -> None:
|
||||||
self._module = module
|
self._module = module
|
||||||
self._modname = modname
|
self._modname = modname
|
||||||
@ -52,7 +55,7 @@ class _ModuleWrapper:
|
|||||||
class DeprecatedDict(dict):
|
class DeprecatedDict(dict):
|
||||||
"""A deprecated dict which warns on each access."""
|
"""A deprecated dict which warns on each access."""
|
||||||
|
|
||||||
def __init__(self, data: Dict, message: str, warning: Type[Warning]) -> None:
|
def __init__(self, data: Dict, message: str, warning: "Type[Warning]") -> None:
|
||||||
self.message = message
|
self.message = message
|
||||||
self.warning = warning
|
self.warning = warning
|
||||||
super().__init__(data)
|
super().__init__(data)
|
||||||
|
@ -10,7 +10,6 @@
|
|||||||
import codecs
|
import codecs
|
||||||
import warnings
|
import warnings
|
||||||
from typing import Any, List
|
from typing import Any, List
|
||||||
from typing import Type # for python3.5.1
|
|
||||||
|
|
||||||
from docutils import nodes
|
from docutils import nodes
|
||||||
from docutils.core import Publisher
|
from docutils.core import Publisher
|
||||||
@ -40,6 +39,7 @@ from sphinx.versioning import UIDTransform
|
|||||||
|
|
||||||
if False:
|
if False:
|
||||||
# For type annotation
|
# For type annotation
|
||||||
|
from typing import Type # for python3.5.1
|
||||||
from sphinx.application import Sphinx
|
from sphinx.application import Sphinx
|
||||||
|
|
||||||
|
|
||||||
@ -80,7 +80,7 @@ class SphinxBaseReader(standalone.Reader):
|
|||||||
self._app = app # hold application object only for compatibility
|
self._app = app # hold application object only for compatibility
|
||||||
self._env = app.env
|
self._env = app.env
|
||||||
|
|
||||||
def get_transforms(self) -> List[Type[Transform]]:
|
def get_transforms(self) -> List["Type[Transform]"]:
|
||||||
transforms = super().get_transforms() + self.transforms
|
transforms = super().get_transforms() + self.transforms
|
||||||
|
|
||||||
# remove transforms which is not needed for Sphinx
|
# remove transforms which is not needed for Sphinx
|
||||||
|
@ -11,7 +11,6 @@
|
|||||||
import re
|
import re
|
||||||
import warnings
|
import warnings
|
||||||
from typing import Any, Dict, List, Tuple
|
from typing import Any, Dict, List, Tuple
|
||||||
from typing import Type # for python3.5.1
|
|
||||||
|
|
||||||
from docutils import nodes, utils
|
from docutils import nodes, utils
|
||||||
from docutils.nodes import Element, Node, TextElement, system_message
|
from docutils.nodes import Element, Node, TextElement, system_message
|
||||||
@ -29,6 +28,7 @@ from sphinx.util.typing import RoleFunction
|
|||||||
|
|
||||||
if False:
|
if False:
|
||||||
# For type annotation
|
# For type annotation
|
||||||
|
from typing import Type # for python3.5.1
|
||||||
from sphinx.application import Sphinx
|
from sphinx.application import Sphinx
|
||||||
from sphinx.environment import BuildEnvironment
|
from sphinx.environment import BuildEnvironment
|
||||||
|
|
||||||
@ -77,7 +77,7 @@ class XRefRole(ReferenceRole):
|
|||||||
innernodeclass = nodes.literal # type: Type[TextElement]
|
innernodeclass = nodes.literal # type: Type[TextElement]
|
||||||
|
|
||||||
def __init__(self, fix_parens: bool = False, lowercase: bool = False,
|
def __init__(self, fix_parens: bool = False, lowercase: bool = False,
|
||||||
nodeclass: Type[Element] = None, innernodeclass: Type[TextElement] = None,
|
nodeclass: "Type[Element]" = None, innernodeclass: "Type[TextElement]" = None,
|
||||||
warn_dangling: bool = False) -> None:
|
warn_dangling: bool = False) -> None:
|
||||||
self.fix_parens = fix_parens
|
self.fix_parens = fix_parens
|
||||||
self.lowercase = lowercase
|
self.lowercase = lowercase
|
||||||
|
Loading…
Reference in New Issue
Block a user