Skip to content

Commit 5d95565

Browse files
authored
FIX: Typing annotations (ipython#12683)
Running `mypy -p IPython.sphinxext` raised a few errors. Fix them and strip some trailing whitespace from a few places.
2 parents 08be4c9 + 209f369 commit 5d95565

File tree

8 files changed

+32
-23
lines changed

8 files changed

+32
-23
lines changed

IPython/core/inputsplitter.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
1616
For more details, see the class docstrings below.
1717
"""
18+
1819
from __future__ import annotations
1920

2021
from warnings import warn

IPython/core/tests/test_inputtransformer2.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
more complex. See test_inputtransformer2_line for tests for line-based
55
transformations.
66
"""
7+
78
import platform
89
import string
910
import sys

IPython/core/tests/test_paths.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -160,14 +160,16 @@ def test_get_ipython_dir_8():
160160
# test only when HOME directory actually writable
161161
return
162162

163-
with patch.object(paths, "_writable_dir", lambda path: bool(path)), patch.object(
164-
paths, "get_xdg_dir", return_value=None
165-
), modified_env(
166-
{
167-
"IPYTHON_DIR": None,
168-
"IPYTHONDIR": None,
169-
"HOME": "/",
170-
}
163+
with (
164+
patch.object(paths, "_writable_dir", lambda path: bool(path)),
165+
patch.object(paths, "get_xdg_dir", return_value=None),
166+
modified_env(
167+
{
168+
"IPYTHON_DIR": None,
169+
"IPYTHONDIR": None,
170+
"HOME": "/",
171+
}
172+
),
171173
):
172174
assert paths.get_ipython_dir() == "/.ipython"
173175

IPython/external/qt_loaders.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
This is used primarily by qt and qt_for_kernel, and shouldn't
99
be accessed directly from the outside
1010
"""
11+
1112
import importlib.abc
1213
import sys
1314
import os

IPython/lib/clipboard.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
""" Utilities for accessing the platform's clipboard.
22
"""
3+
34
import os
45
import subprocess
56

IPython/sphinxext/custom_doctests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def float_doctest(sphinx_shell, args, input_lines, found, submitted):
107107
try:
108108
rtol = float(args[2])
109109
atol = float(args[3])
110-
except IndexError as e:
110+
except IndexError:
111111
e = ("Both `rtol` and `atol` must be specified "
112112
"if either are specified: {0}".format(args))
113113
raise IndexError(e) from e

IPython/sphinxext/ipython_directive.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@
174174

175175
# Authors
176176
# =======
177-
#
177+
#
178178
# - John D Hunter: original author.
179179
# - Fernando Perez: refactoring, documentation, cleanups, port to 0.11.
180180
# - VáclavŠmilauer <eudoxos-AT-arcig.cz>: Prompt generalizations.
@@ -196,6 +196,7 @@
196196
import warnings
197197
import shutil
198198
from io import StringIO
199+
from typing import Any, Dict, Set
199200

200201
# Third-party
201202
from docutils.parsers.rst import directives
@@ -425,7 +426,7 @@ def process_image(self, decorator):
425426
source_dir = self.source_dir
426427
saveargs = decorator.split(' ')
427428
filename = saveargs[1]
428-
# insert relative path to image file in source
429+
# insert relative path to image file in source
429430
# as absolute path for Sphinx
430431
# sphinx expects a posix path, even on Windows
431432
path = pathlib.Path(savefig_dir, filename)
@@ -901,21 +902,22 @@ def custom_doctest(self, decorator, input_lines, found, submitted):
901902

902903
class IPythonDirective(Directive):
903904

904-
has_content = True
905-
required_arguments = 0
906-
optional_arguments = 4 # python, suppress, verbatim, doctest
907-
final_argumuent_whitespace = True
908-
option_spec = { 'python': directives.unchanged,
909-
'suppress' : directives.flag,
910-
'verbatim' : directives.flag,
911-
'doctest' : directives.flag,
912-
'okexcept': directives.flag,
913-
'okwarning': directives.flag
914-
}
905+
has_content: bool = True
906+
required_arguments: int = 0
907+
optional_arguments: int = 4 # python, suppress, verbatim, doctest
908+
final_argumuent_whitespace: bool = True
909+
option_spec: Dict[str, Any] = {
910+
"python": directives.unchanged,
911+
"suppress": directives.flag,
912+
"verbatim": directives.flag,
913+
"doctest": directives.flag,
914+
"okexcept": directives.flag,
915+
"okwarning": directives.flag,
916+
}
915917

916918
shell = None
917919

918-
seen_docs = set()
920+
seen_docs: Set = set()
919921

920922
def get_config_options(self):
921923
# contains sphinx configuration variables

IPython/terminal/shortcuts/auto_match.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
This will be bound to specific key press and filter modes,
55
like whether we are in edit mode, and whether the completer is open.
66
"""
7+
78
import re
89
from prompt_toolkit.key_binding import KeyPressEvent
910

0 commit comments

Comments
 (0)