##// END OF EJS Templates
stricter types
M Bussonnier -
Show More
@@ -10,12 +10,18 b' Inheritance diagram:'
10 10 import os
11 11 import re
12 12 import string
13 import sys
13 14 import textwrap
14 15 import warnings
15 16 from string import Formatter
16 17 from pathlib import Path
17 18
18 from typing import List, Dict, Tuple, Optional, cast
19 from typing import List, Dict, Tuple, Optional, cast, Sequence, Mapping, Any
20
21 if sys.version_info < (3, 12):
22 from typing_extensions import Self
23 else:
24 from typing import Self
19 25
20 26
21 27 class LSString(str):
@@ -34,7 +40,11 b' class LSString(str):'
34 40 Such strings are very useful to efficiently interact with the shell, which
35 41 typically only understands whitespace-separated options for commands."""
36 42
37 def get_list(self):
43 __list: List[str]
44 __spstr: str
45 __paths: List[Path]
46
47 def get_list(self) -> List[str]:
38 48 try:
39 49 return self.__list
40 50 except AttributeError:
@@ -43,7 +53,7 b' class LSString(str):'
43 53
44 54 l = list = property(get_list)
45 55
46 def get_spstr(self):
56 def get_spstr(self) -> str:
47 57 try:
48 58 return self.__spstr
49 59 except AttributeError:
@@ -52,12 +62,12 b' class LSString(str):'
52 62
53 63 s = spstr = property(get_spstr)
54 64
55 def get_nlstr(self):
65 def get_nlstr(self) -> Self:
56 66 return self
57 67
58 68 n = nlstr = property(get_nlstr)
59 69
60 def get_paths(self):
70 def get_paths(self) -> List[Path]:
61 71 try:
62 72 return self.__paths
63 73 except AttributeError:
@@ -92,12 +102,16 b' class SList(list):'
92 102 Any values which require transformations are computed only once and
93 103 cached."""
94 104
95 def get_list(self):
105 __spstr: str
106 __nlstr: str
107 __paths: List[Path]
108
109 def get_list(self) -> Self:
96 110 return self
97 111
98 112 l = list = property(get_list)
99 113
100 def get_spstr(self):
114 def get_spstr(self) -> str:
101 115 try:
102 116 return self.__spstr
103 117 except AttributeError:
@@ -106,7 +120,7 b' class SList(list):'
106 120
107 121 s = spstr = property(get_spstr)
108 122
109 def get_nlstr(self):
123 def get_nlstr(self) -> str:
110 124 try:
111 125 return self.__nlstr
112 126 except AttributeError:
@@ -115,7 +129,7 b' class SList(list):'
115 129
116 130 n = nlstr = property(get_nlstr)
117 131
118 def get_paths(self):
132 def get_paths(self) -> List[Path]:
119 133 try:
120 134 return self.__paths
121 135 except AttributeError:
@@ -538,7 +552,9 b' class FullEvalFormatter(Formatter):'
538 552 """
539 553 # copied from Formatter._vformat with minor changes to allow eval
540 554 # and replace the format_spec code with slicing
541 def vformat(self, format_string: str, args, kwargs) -> str:
555 def vformat(
556 self, format_string: str, args: Sequence[Any], kwargs: Mapping[str, Any]
557 ) -> str:
542 558 result = []
543 559 conversion: Optional[str]
544 560 for literal_text, field_name, format_spec, conversion in self.parse(
@@ -559,7 +575,7 b' class FullEvalFormatter(Formatter):'
559 575
560 576 # eval the contents of the field for the object
561 577 # to be formatted
562 obj = eval(field_name, kwargs)
578 obj = eval(field_name, dict(kwargs))
563 579
564 580 # do any conversion on the resulting object
565 581 # type issue in typeshed, fined in https://github.com/python/typeshed/pull/11377
@@ -629,7 +645,9 b' def _col_chunks(l, max_rows, row_first=False):'
629 645 yield l[i:(i + max_rows)]
630 646
631 647
632 def _find_optimal(rlist, row_first: bool, separator_size: int, displaywidth: int):
648 def _find_optimal(
649 rlist: List[str], row_first: bool, separator_size: int, displaywidth: int
650 ) -> Dict[str, Any]:
633 651 """Calculate optimal info to columnize a list of string"""
634 652 for max_rows in range(1, len(rlist) + 1):
635 653 col_widths = list(map(max, _col_chunks(rlist, max_rows, row_first)))
@@ -653,7 +671,12 b' def _get_or_default(mylist, i, default=None):'
653 671
654 672
655 673 def compute_item_matrix(
656 items, row_first: bool = False, empty=None, *, separator_size=2, displaywidth=80
674 items: List[str],
675 row_first: bool = False,
676 empty: Optional[str] = None,
677 *,
678 separator_size: int = 2,
679 displaywidth: int = 80,
657 680 ) -> Tuple[List[List[int]], Dict[str, int]]:
658 681 """Returns a nested list, and info to columnize items
659 682
@@ -710,7 +733,7 b' def compute_item_matrix('
710 733 category=PendingDeprecationWarning,
711 734 )
712 735 info = _find_optimal(
713 list(map(len, items)),
736 list(map(len, items)), # type: ignore[arg-type]
714 737 row_first,
715 738 separator_size=separator_size,
716 739 displaywidth=displaywidth,
@@ -728,7 +751,7 b' def columnize('
728 751 separator: str = " ",
729 752 displaywidth: int = 80,
730 753 spread: bool = False,
731 ):
754 ) -> str:
732 755 """Transform a list of strings into a single string with columns.
733 756
734 757 Parameters
@@ -136,6 +136,164 b' exclude = ['
136 136 'IPython/utils/_process_win32.py',
137 137 'IPython/utils/path.py',
138 138 ]
139 disallow_untyped_defs = true
140 # ignore_errors = false
141 # ignore_missing_imports = false
142 # disallow_untyped_calls = true
143 disallow_incomplete_defs = true
144 # check_untyped_defs = true
145 # disallow_untyped_decorators = true
146 warn_redundant_casts = true
147
148 [[tool.mypy.overrides]]
149 module = [
150 "IPython.utils.text",
151 ]
152 disallow_untyped_defs = false
153 check_untyped_defs = false
154 disallow_untyped_decorators = false
155
156
157 # gloabl ignore error
158 [[tool.mypy.overrides]]
159 module = [
160 "IPython",
161 "IPython.conftest",
162 "IPython.core.alias",
163 "IPython.core.async_helpers",
164 "IPython.core.autocall",
165 "IPython.core.builtin_trap",
166 "IPython.core.compilerop",
167 "IPython.core.completer",
168 "IPython.core.completerlib",
169 "IPython.core.crashhandler",
170 "IPython.core.debugger",
171 "IPython.core.display",
172 "IPython.core.display_functions",
173 "IPython.core.display_trap",
174 "IPython.core.displayhook",
175 "IPython.core.displaypub",
176 "IPython.core.events",
177 "IPython.core.excolors",
178 "IPython.core.extensions",
179 "IPython.core.formatters",
180 "IPython.core.getipython",
181 "IPython.core.guarded_eval",
182 "IPython.core.history",
183 "IPython.core.historyapp",
184 "IPython.core.hooks",
185 "IPython.core.inputsplitter",
186 "IPython.core.inputtransformer",
187 "IPython.core.inputtransformer2",
188 "IPython.core.interactiveshell",
189 "IPython.core.logger",
190 "IPython.core.macro",
191 "IPython.core.magic",
192 "IPython.core.magic_arguments",
193 "IPython.core.magics.ast_mod",
194 "IPython.core.magics.auto",
195 "IPython.core.magics.basic",
196 "IPython.core.magics.code",
197 "IPython.core.magics.config",
198 "IPython.core.magics.display",
199 "IPython.core.magics.execution",
200 "IPython.core.magics.extension",
201 "IPython.core.magics.history",
202 "IPython.core.magics.logging",
203 "IPython.core.magics.namespace",
204 "IPython.core.magics.osm",
205 "IPython.core.magics.packaging",
206 "IPython.core.magics.pylab",
207 "IPython.core.magics.script",
208 "IPython.core.oinspect",
209 "IPython.core.page",
210 "IPython.core.payload",
211 "IPython.core.payloadpage",
212 "IPython.core.prefilter",
213 "IPython.core.profiledir",
214 "IPython.core.prompts",
215 "IPython.core.pylabtools",
216 "IPython.core.shellapp",
217 "IPython.core.splitinput",
218 "IPython.core.ultratb",
219 "IPython.extensions.autoreload",
220 "IPython.extensions.storemagic",
221 "IPython.external.qt_for_kernel",
222 "IPython.external.qt_loaders",
223 "IPython.lib.backgroundjobs",
224 "IPython.lib.clipboard",
225 "IPython.lib.demo",
226 "IPython.lib.display",
227 "IPython.lib.editorhooks",
228 "IPython.lib.guisupport",
229 "IPython.lib.latextools",
230 "IPython.lib.lexers",
231 "IPython.lib.pretty",
232 "IPython.paths",
233 "IPython.sphinxext.ipython_console_highlighting",
234 "IPython.terminal.debugger",
235 "IPython.terminal.embed",
236 "IPython.terminal.interactiveshell",
237 "IPython.terminal.magics",
238 "IPython.terminal.prompts",
239 "IPython.terminal.pt_inputhooks",
240 "IPython.terminal.pt_inputhooks.asyncio",
241 "IPython.terminal.pt_inputhooks.glut",
242 "IPython.terminal.pt_inputhooks.gtk",
243 "IPython.terminal.pt_inputhooks.gtk3",
244 "IPython.terminal.pt_inputhooks.gtk4",
245 "IPython.terminal.pt_inputhooks.osx",
246 "IPython.terminal.pt_inputhooks.pyglet",
247 "IPython.terminal.pt_inputhooks.qt",
248 "IPython.terminal.pt_inputhooks.tk",
249 "IPython.terminal.pt_inputhooks.wx",
250 "IPython.terminal.ptutils",
251 "IPython.terminal.shortcuts",
252 "IPython.terminal.shortcuts.auto_match",
253 "IPython.terminal.shortcuts.auto_suggest",
254 "IPython.terminal.shortcuts.filters",
255 "IPython.utils._process_cli",
256 "IPython.utils._process_common",
257 "IPython.utils._process_emscripten",
258 "IPython.utils._process_posix",
259 "IPython.utils.capture",
260 "IPython.utils.coloransi",
261 "IPython.utils.contexts",
262 "IPython.utils.data",
263 "IPython.utils.decorators",
264 "IPython.utils.dir2",
265 "IPython.utils.encoding",
266 "IPython.utils.frame",
267 "IPython.utils.generics",
268 "IPython.utils.importstring",
269 "IPython.utils.io",
270 "IPython.utils.ipstruct",
271 "IPython.utils.module_paths",
272 "IPython.utils.openpy",
273 "IPython.utils.process",
274 "IPython.utils.py3compat",
275 "IPython.utils.sentinel",
276 "IPython.utils.shimmodule",
277 "IPython.utils.strdispatch",
278 "IPython.utils.sysinfo",
279 "IPython.utils.syspathcontext",
280 "IPython.utils.tempdir",
281 "IPython.utils.terminal",
282 "IPython.utils.timing",
283 "IPython.utils.tokenutil",
284 "IPython.utils.tz",
285 "IPython.utils.ulinecache",
286 "IPython.utils.version",
287 "IPython.utils.wildcard",
288
289 ]
290 disallow_untyped_defs = false
291 ignore_errors = true
292 ignore_missing_imports = true
293 disallow_untyped_calls = false
294 disallow_incomplete_defs = false
295 check_untyped_defs = false
296 disallow_untyped_decorators = false
139 297
140 298 [tool.pytest.ini_options]
141 299 addopts = [
General Comments 0
You need to be logged in to leave comments. Login now