From c8d946943a8c04795d01443099fcb1b93b6020c4 Mon Sep 17 00:00:00 2001 From: farisachugthai Date: Wed, 28 Oct 2020 12:38:14 -0400 Subject: [PATCH] FIX: Typing annotations Running `mypy -p IPython.sphinxext` raised a few errors. Fix them and strip some trailing whitespace from a few places. --- IPython/sphinxext/custom_doctests.py | 2 +- IPython/sphinxext/ipython_directive.py | 17 +++++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/IPython/sphinxext/custom_doctests.py b/IPython/sphinxext/custom_doctests.py index 75c2a25ccb7..f0ea034a6db 100644 --- a/IPython/sphinxext/custom_doctests.py +++ b/IPython/sphinxext/custom_doctests.py @@ -107,7 +107,7 @@ def float_doctest(sphinx_shell, args, input_lines, found, submitted): try: rtol = float(args[2]) atol = float(args[3]) - except IndexError as e: + except IndexError: e = ("Both `rtol` and `atol` must be specified " "if either are specified: {0}".format(args)) raise IndexError(e) from e diff --git a/IPython/sphinxext/ipython_directive.py b/IPython/sphinxext/ipython_directive.py index 88357a51137..af4bfed5a90 100644 --- a/IPython/sphinxext/ipython_directive.py +++ b/IPython/sphinxext/ipython_directive.py @@ -174,7 +174,7 @@ # Authors # ======= -# +# # - John D Hunter: original author. # - Fernando Perez: refactoring, documentation, cleanups, port to 0.11. # - VáclavŠmilauer : Prompt generalizations. @@ -196,6 +196,7 @@ import warnings import shutil from io import StringIO +from typing import Any, Dict, Set # Third-party from docutils.parsers.rst import directives @@ -425,7 +426,7 @@ def process_image(self, decorator): source_dir = self.source_dir saveargs = decorator.split(' ') filename = saveargs[1] - # insert relative path to image file in source + # insert relative path to image file in source # as absolute path for Sphinx # sphinx expects a posix path, even on Windows path = pathlib.Path(savefig_dir, filename) @@ -901,11 +902,11 @@ def custom_doctest(self, decorator, input_lines, found, submitted): class IPythonDirective(Directive): - has_content = True - required_arguments = 0 - optional_arguments = 4 # python, suppress, verbatim, doctest - final_argumuent_whitespace = True - option_spec = { 'python': directives.unchanged, + has_content: bool = True + required_arguments: int = 0 + optional_arguments: int = 4 # python, suppress, verbatim, doctest + final_argumuent_whitespace: bool = True + option_spec: Dict[str, Any] = { 'python': directives.unchanged, 'suppress' : directives.flag, 'verbatim' : directives.flag, 'doctest' : directives.flag, @@ -915,7 +916,7 @@ class IPythonDirective(Directive): shell = None - seen_docs = set() + seen_docs: Set = set() def get_config_options(self): # contains sphinx configuration variables