summaryrefslogtreecommitdiff
path: root/sphinx/util/pycompat.py
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2020-05-04 01:58:00 +0900
committerGitHub <noreply@github.com>2020-05-04 01:58:00 +0900
commitc13ecd243709d1e210a030be5aa09b7714e35730 (patch)
treea360e28b14a9f6c2d0ea57f5178ec501f7eb74ee /sphinx/util/pycompat.py
parenta5036270c8f14167bd58cc5768081e904574fa2a (diff)
parent3fee5a1ad8d2eff56403b8b7167f3de5fdcc8b03 (diff)
downloadsphinx-git-c13ecd243709d1e210a030be5aa09b7714e35730.tar.gz
Merge pull request #7606 from tk0miya/deprecation
refactor: Catch ImportError for lib2to3 to support future python
Diffstat (limited to 'sphinx/util/pycompat.py')
-rw-r--r--sphinx/util/pycompat.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/sphinx/util/pycompat.py b/sphinx/util/pycompat.py
index 061bbcb6d..6decc1cef 100644
--- a/sphinx/util/pycompat.py
+++ b/sphinx/util/pycompat.py
@@ -31,8 +31,15 @@ logger = logging.getLogger(__name__)
# convert_with_2to3():
# support for running 2to3 over config files
def convert_with_2to3(filepath: str) -> str:
- from lib2to3.refactor import RefactoringTool, get_fixers_from_package
- from lib2to3.pgen2.parse import ParseError
+ try:
+ from lib2to3.refactor import RefactoringTool, get_fixers_from_package
+ from lib2to3.pgen2.parse import ParseError
+ except ImportError:
+ # python 3.9.0a6+ emits PendingDeprecationWarning for lib2to3.
+ # Additionally, removal of the module is still discussed at PEP-594.
+ # To support future python, this catches ImportError for lib2to3.
+ raise SyntaxError
+
fixers = get_fixers_from_package('lib2to3.fixes')
refactoring_tool = RefactoringTool(fixers)
source = refactoring_tool._read_python_source(filepath)[0]