Show More
The requested changes are too big and content was truncated. Show full diff
|
1 | NO CONTENT: modified file | |
The requested commit or file is too big and content was truncated. Show full diff |
@@ -1,1098 +1,1154 b'' | |||
|
1 | 1 | # -*- coding: utf-8 -*- |
|
2 | 2 | """Tools for inspecting Python objects. |
|
3 | 3 | |
|
4 | 4 | Uses syntax highlighting for presenting the various information elements. |
|
5 | 5 | |
|
6 | 6 | Similar in spirit to the inspect module, but all calls take a name argument to |
|
7 | 7 | reference the name under which an object is being read. |
|
8 | 8 | """ |
|
9 | 9 | |
|
10 | 10 | # Copyright (c) IPython Development Team. |
|
11 | 11 | # Distributed under the terms of the Modified BSD License. |
|
12 | 12 | |
|
13 | 13 | __all__ = ['Inspector','InspectColors'] |
|
14 | 14 | |
|
15 | 15 | # stdlib modules |
|
16 | import ast | |
|
17 | import inspect | |
|
16 | from dataclasses import dataclass | |
|
18 | 17 | from inspect import signature |
|
18 | from textwrap import dedent | |
|
19 | import ast | |
|
19 | 20 | import html |
|
21 | import inspect | |
|
22 | import io as stdlib_io | |
|
20 | 23 | import linecache |
|
21 | import warnings | |
|
22 | 24 | import os |
|
23 | from textwrap import dedent | |
|
25 | import sys | |
|
24 | 26 | import types |
|
25 | import io as stdlib_io | |
|
27 | import warnings | |
|
26 | 28 | |
|
27 | from typing import Union | |
|
29 | from typing import Any, Optional, Dict, Union, List, Tuple | |
|
30 | ||
|
31 | if sys.version_info <= (3, 10): | |
|
32 | from typing_extensions import TypeAlias | |
|
33 | else: | |
|
34 | from typing import TypeAlias | |
|
28 | 35 | |
|
29 | 36 | # IPython's own |
|
30 | 37 | from IPython.core import page |
|
31 | 38 | from IPython.lib.pretty import pretty |
|
32 | 39 | from IPython.testing.skipdoctest import skip_doctest |
|
33 | 40 | from IPython.utils import PyColorize |
|
34 | 41 | from IPython.utils import openpy |
|
35 | 42 | from IPython.utils.dir2 import safe_hasattr |
|
36 | 43 | from IPython.utils.path import compress_user |
|
37 | 44 | from IPython.utils.text import indent |
|
38 | 45 | from IPython.utils.wildcard import list_namespace |
|
39 | 46 | from IPython.utils.wildcard import typestr2type |
|
40 | 47 | from IPython.utils.coloransi import TermColors, ColorScheme, ColorSchemeTable |
|
41 | 48 | from IPython.utils.py3compat import cast_unicode |
|
42 | 49 | from IPython.utils.colorable import Colorable |
|
43 | 50 | from IPython.utils.decorators import undoc |
|
44 | 51 | |
|
45 | 52 | from pygments import highlight |
|
46 | 53 | from pygments.lexers import PythonLexer |
|
47 | 54 | from pygments.formatters import HtmlFormatter |
|
48 | 55 | |
|
49 | from typing import Any, Optional | |
|
50 | from dataclasses import dataclass | |
|
56 | HOOK_NAME = "__custom_documentations__" | |
|
57 | ||
|
58 | ||
|
59 | UnformattedBundle: TypeAlias = Dict[str, List[Tuple[str, str]]] # List of (title, body) | |
|
60 | Bundle: TypeAlias = Dict[str, str] | |
|
51 | 61 | |
|
52 | 62 | |
|
53 | 63 | @dataclass |
|
54 | 64 | class OInfo: |
|
55 | 65 | ismagic: bool |
|
56 | 66 | isalias: bool |
|
57 | 67 | found: bool |
|
58 | 68 | namespace: Optional[str] |
|
59 | 69 | parent: Any |
|
60 | 70 | obj: Any |
|
61 | 71 | |
|
62 | 72 | def pylight(code): |
|
63 | 73 | return highlight(code, PythonLexer(), HtmlFormatter(noclasses=True)) |
|
64 | 74 | |
|
65 | 75 | # builtin docstrings to ignore |
|
66 | 76 | _func_call_docstring = types.FunctionType.__call__.__doc__ |
|
67 | 77 | _object_init_docstring = object.__init__.__doc__ |
|
68 | 78 | _builtin_type_docstrings = { |
|
69 | 79 | inspect.getdoc(t) for t in (types.ModuleType, types.MethodType, |
|
70 | 80 | types.FunctionType, property) |
|
71 | 81 | } |
|
72 | 82 | |
|
73 | 83 | _builtin_func_type = type(all) |
|
74 | 84 | _builtin_meth_type = type(str.upper) # Bound methods have the same type as builtin functions |
|
75 | 85 | #**************************************************************************** |
|
76 | 86 | # Builtin color schemes |
|
77 | 87 | |
|
78 | 88 | Colors = TermColors # just a shorthand |
|
79 | 89 | |
|
80 | 90 | InspectColors = PyColorize.ANSICodeColors |
|
81 | 91 | |
|
82 | 92 | #**************************************************************************** |
|
83 | 93 | # Auxiliary functions and objects |
|
84 | 94 | |
|
85 | 95 | # See the messaging spec for the definition of all these fields. This list |
|
86 | 96 | # effectively defines the order of display |
|
87 | 97 | info_fields = ['type_name', 'base_class', 'string_form', 'namespace', |
|
88 | 98 | 'length', 'file', 'definition', 'docstring', 'source', |
|
89 | 99 | 'init_definition', 'class_docstring', 'init_docstring', |
|
90 | 100 | 'call_def', 'call_docstring', |
|
91 | 101 | # These won't be printed but will be used to determine how to |
|
92 | 102 | # format the object |
|
93 | 103 | 'ismagic', 'isalias', 'isclass', 'found', 'name' |
|
94 | 104 | ] |
|
95 | 105 | |
|
96 | 106 | |
|
97 | 107 | def object_info(**kw): |
|
98 | 108 | """Make an object info dict with all fields present.""" |
|
99 | 109 | infodict = {k:None for k in info_fields} |
|
100 | 110 | infodict.update(kw) |
|
101 | 111 | return infodict |
|
102 | 112 | |
|
103 | 113 | |
|
104 | 114 | def get_encoding(obj): |
|
105 | 115 | """Get encoding for python source file defining obj |
|
106 | 116 | |
|
107 | 117 | Returns None if obj is not defined in a sourcefile. |
|
108 | 118 | """ |
|
109 | 119 | ofile = find_file(obj) |
|
110 | 120 | # run contents of file through pager starting at line where the object |
|
111 | 121 | # is defined, as long as the file isn't binary and is actually on the |
|
112 | 122 | # filesystem. |
|
113 | 123 | if ofile is None: |
|
114 | 124 | return None |
|
115 | 125 | elif ofile.endswith(('.so', '.dll', '.pyd')): |
|
116 | 126 | return None |
|
117 | 127 | elif not os.path.isfile(ofile): |
|
118 | 128 | return None |
|
119 | 129 | else: |
|
120 | 130 | # Print only text files, not extension binaries. Note that |
|
121 | 131 | # getsourcelines returns lineno with 1-offset and page() uses |
|
122 | 132 | # 0-offset, so we must adjust. |
|
123 | 133 | with stdlib_io.open(ofile, 'rb') as buffer: # Tweaked to use io.open for Python 2 |
|
124 | 134 | encoding, lines = openpy.detect_encoding(buffer.readline) |
|
125 | 135 | return encoding |
|
126 | 136 | |
|
127 | 137 | def getdoc(obj) -> Union[str,None]: |
|
128 | 138 | """Stable wrapper around inspect.getdoc. |
|
129 | 139 | |
|
130 | 140 | This can't crash because of attribute problems. |
|
131 | 141 | |
|
132 | 142 | It also attempts to call a getdoc() method on the given object. This |
|
133 | 143 | allows objects which provide their docstrings via non-standard mechanisms |
|
134 | 144 | (like Pyro proxies) to still be inspected by ipython's ? system. |
|
135 | 145 | """ |
|
136 | 146 | # Allow objects to offer customized documentation via a getdoc method: |
|
137 | 147 | try: |
|
138 | 148 | ds = obj.getdoc() |
|
139 | 149 | except Exception: |
|
140 | 150 | pass |
|
141 | 151 | else: |
|
142 | 152 | if isinstance(ds, str): |
|
143 | 153 | return inspect.cleandoc(ds) |
|
144 | 154 | docstr = inspect.getdoc(obj) |
|
145 | 155 | return docstr |
|
146 | 156 | |
|
147 | 157 | |
|
148 | 158 | def getsource(obj, oname='') -> Union[str,None]: |
|
149 | 159 | """Wrapper around inspect.getsource. |
|
150 | 160 | |
|
151 | 161 | This can be modified by other projects to provide customized source |
|
152 | 162 | extraction. |
|
153 | 163 | |
|
154 | 164 | Parameters |
|
155 | 165 | ---------- |
|
156 | 166 | obj : object |
|
157 | 167 | an object whose source code we will attempt to extract |
|
158 | 168 | oname : str |
|
159 | 169 | (optional) a name under which the object is known |
|
160 | 170 | |
|
161 | 171 | Returns |
|
162 | 172 | ------- |
|
163 | 173 | src : unicode or None |
|
164 | 174 | |
|
165 | 175 | """ |
|
166 | 176 | |
|
167 | 177 | if isinstance(obj, property): |
|
168 | 178 | sources = [] |
|
169 | 179 | for attrname in ['fget', 'fset', 'fdel']: |
|
170 | 180 | fn = getattr(obj, attrname) |
|
171 | 181 | if fn is not None: |
|
172 | 182 | encoding = get_encoding(fn) |
|
173 | 183 | oname_prefix = ('%s.' % oname) if oname else '' |
|
174 | 184 | sources.append(''.join(('# ', oname_prefix, attrname))) |
|
175 | 185 | if inspect.isfunction(fn): |
|
176 | 186 | _src = getsource(fn) |
|
177 | 187 | if _src: |
|
178 | 188 | # assert _src is not None, "please mypy" |
|
179 | 189 | sources.append(dedent(_src)) |
|
180 | 190 | else: |
|
181 | 191 | # Default str/repr only prints function name, |
|
182 | 192 | # pretty.pretty prints module name too. |
|
183 | 193 | sources.append( |
|
184 | 194 | '%s%s = %s\n' % (oname_prefix, attrname, pretty(fn)) |
|
185 | 195 | ) |
|
186 | 196 | if sources: |
|
187 | 197 | return '\n'.join(sources) |
|
188 | 198 | else: |
|
189 | 199 | return None |
|
190 | 200 | |
|
191 | 201 | else: |
|
192 | 202 | # Get source for non-property objects. |
|
193 | 203 | |
|
194 | 204 | obj = _get_wrapped(obj) |
|
195 | 205 | |
|
196 | 206 | try: |
|
197 | 207 | src = inspect.getsource(obj) |
|
198 | 208 | except TypeError: |
|
199 | 209 | # The object itself provided no meaningful source, try looking for |
|
200 | 210 | # its class definition instead. |
|
201 | 211 | try: |
|
202 | 212 | src = inspect.getsource(obj.__class__) |
|
203 | 213 | except (OSError, TypeError): |
|
204 | 214 | return None |
|
205 | 215 | except OSError: |
|
206 | 216 | return None |
|
207 | 217 | |
|
208 | 218 | return src |
|
209 | 219 | |
|
210 | 220 | |
|
211 | 221 | def is_simple_callable(obj): |
|
212 | 222 | """True if obj is a function ()""" |
|
213 | 223 | return (inspect.isfunction(obj) or inspect.ismethod(obj) or \ |
|
214 | 224 | isinstance(obj, _builtin_func_type) or isinstance(obj, _builtin_meth_type)) |
|
215 | 225 | |
|
216 | 226 | @undoc |
|
217 | 227 | def getargspec(obj): |
|
218 | 228 | """Wrapper around :func:`inspect.getfullargspec` |
|
219 | 229 | |
|
220 | 230 | In addition to functions and methods, this can also handle objects with a |
|
221 | 231 | ``__call__`` attribute. |
|
222 | 232 | |
|
223 | 233 | DEPRECATED: Deprecated since 7.10. Do not use, will be removed. |
|
224 | 234 | """ |
|
225 | 235 | |
|
226 | 236 | warnings.warn('`getargspec` function is deprecated as of IPython 7.10' |
|
227 | 237 | 'and will be removed in future versions.', DeprecationWarning, stacklevel=2) |
|
228 | 238 | |
|
229 | 239 | if safe_hasattr(obj, '__call__') and not is_simple_callable(obj): |
|
230 | 240 | obj = obj.__call__ |
|
231 | 241 | |
|
232 | 242 | return inspect.getfullargspec(obj) |
|
233 | 243 | |
|
234 | 244 | @undoc |
|
235 | 245 | def format_argspec(argspec): |
|
236 | 246 | """Format argspect, convenience wrapper around inspect's. |
|
237 | 247 | |
|
238 | 248 | This takes a dict instead of ordered arguments and calls |
|
239 | 249 | inspect.format_argspec with the arguments in the necessary order. |
|
240 | 250 | |
|
241 | 251 | DEPRECATED (since 7.10): Do not use; will be removed in future versions. |
|
242 | 252 | """ |
|
243 | 253 | |
|
244 | 254 | warnings.warn('`format_argspec` function is deprecated as of IPython 7.10' |
|
245 | 255 | 'and will be removed in future versions.', DeprecationWarning, stacklevel=2) |
|
246 | 256 | |
|
247 | 257 | |
|
248 | 258 | return inspect.formatargspec(argspec['args'], argspec['varargs'], |
|
249 | 259 | argspec['varkw'], argspec['defaults']) |
|
250 | 260 | |
|
251 | 261 | @undoc |
|
252 | 262 | def call_tip(oinfo, format_call=True): |
|
253 | 263 | """DEPRECATED since 6.0. Extract call tip data from an oinfo dict.""" |
|
254 | 264 | warnings.warn( |
|
255 | 265 | "`call_tip` function is deprecated as of IPython 6.0" |
|
256 | 266 | "and will be removed in future versions.", |
|
257 | 267 | DeprecationWarning, |
|
258 | 268 | stacklevel=2, |
|
259 | 269 | ) |
|
260 | 270 | # Get call definition |
|
261 | 271 | argspec = oinfo.get('argspec') |
|
262 | 272 | if argspec is None: |
|
263 | 273 | call_line = None |
|
264 | 274 | else: |
|
265 | 275 | # Callable objects will have 'self' as their first argument, prune |
|
266 | 276 | # it out if it's there for clarity (since users do *not* pass an |
|
267 | 277 | # extra first argument explicitly). |
|
268 | 278 | try: |
|
269 | 279 | has_self = argspec['args'][0] == 'self' |
|
270 | 280 | except (KeyError, IndexError): |
|
271 | 281 | pass |
|
272 | 282 | else: |
|
273 | 283 | if has_self: |
|
274 | 284 | argspec['args'] = argspec['args'][1:] |
|
275 | 285 | |
|
276 | 286 | call_line = oinfo['name']+format_argspec(argspec) |
|
277 | 287 | |
|
278 | 288 | # Now get docstring. |
|
279 | 289 | # The priority is: call docstring, constructor docstring, main one. |
|
280 | 290 | doc = oinfo.get('call_docstring') |
|
281 | 291 | if doc is None: |
|
282 | 292 | doc = oinfo.get('init_docstring') |
|
283 | 293 | if doc is None: |
|
284 | 294 | doc = oinfo.get('docstring','') |
|
285 | 295 | |
|
286 | 296 | return call_line, doc |
|
287 | 297 | |
|
288 | 298 | |
|
289 | 299 | def _get_wrapped(obj): |
|
290 | 300 | """Get the original object if wrapped in one or more @decorators |
|
291 | 301 | |
|
292 | 302 | Some objects automatically construct similar objects on any unrecognised |
|
293 | 303 | attribute access (e.g. unittest.mock.call). To protect against infinite loops, |
|
294 | 304 | this will arbitrarily cut off after 100 levels of obj.__wrapped__ |
|
295 | 305 | attribute access. --TK, Jan 2016 |
|
296 | 306 | """ |
|
297 | 307 | orig_obj = obj |
|
298 | 308 | i = 0 |
|
299 | 309 | while safe_hasattr(obj, '__wrapped__'): |
|
300 | 310 | obj = obj.__wrapped__ |
|
301 | 311 | i += 1 |
|
302 | 312 | if i > 100: |
|
303 | 313 | # __wrapped__ is probably a lie, so return the thing we started with |
|
304 | 314 | return orig_obj |
|
305 | 315 | return obj |
|
306 | 316 | |
|
307 | 317 | def find_file(obj) -> str: |
|
308 | 318 | """Find the absolute path to the file where an object was defined. |
|
309 | 319 | |
|
310 | 320 | This is essentially a robust wrapper around `inspect.getabsfile`. |
|
311 | 321 | |
|
312 | 322 | Returns None if no file can be found. |
|
313 | 323 | |
|
314 | 324 | Parameters |
|
315 | 325 | ---------- |
|
316 | 326 | obj : any Python object |
|
317 | 327 | |
|
318 | 328 | Returns |
|
319 | 329 | ------- |
|
320 | 330 | fname : str |
|
321 | 331 | The absolute path to the file where the object was defined. |
|
322 | 332 | """ |
|
323 | 333 | obj = _get_wrapped(obj) |
|
324 | 334 | |
|
325 | 335 | fname = None |
|
326 | 336 | try: |
|
327 | 337 | fname = inspect.getabsfile(obj) |
|
328 | 338 | except TypeError: |
|
329 | 339 | # For an instance, the file that matters is where its class was |
|
330 | 340 | # declared. |
|
331 | 341 | try: |
|
332 | 342 | fname = inspect.getabsfile(obj.__class__) |
|
333 | 343 | except (OSError, TypeError): |
|
334 | 344 | # Can happen for builtins |
|
335 | 345 | pass |
|
336 | 346 | except OSError: |
|
337 | 347 | pass |
|
338 | 348 | |
|
339 | 349 | return cast_unicode(fname) |
|
340 | 350 | |
|
341 | 351 | |
|
342 | 352 | def find_source_lines(obj): |
|
343 | 353 | """Find the line number in a file where an object was defined. |
|
344 | 354 | |
|
345 | 355 | This is essentially a robust wrapper around `inspect.getsourcelines`. |
|
346 | 356 | |
|
347 | 357 | Returns None if no file can be found. |
|
348 | 358 | |
|
349 | 359 | Parameters |
|
350 | 360 | ---------- |
|
351 | 361 | obj : any Python object |
|
352 | 362 | |
|
353 | 363 | Returns |
|
354 | 364 | ------- |
|
355 | 365 | lineno : int |
|
356 | 366 | The line number where the object definition starts. |
|
357 | 367 | """ |
|
358 | 368 | obj = _get_wrapped(obj) |
|
359 | 369 | |
|
360 | 370 | try: |
|
361 | 371 | lineno = inspect.getsourcelines(obj)[1] |
|
362 | 372 | except TypeError: |
|
363 | 373 | # For instances, try the class object like getsource() does |
|
364 | 374 | try: |
|
365 | 375 | lineno = inspect.getsourcelines(obj.__class__)[1] |
|
366 | 376 | except (OSError, TypeError): |
|
367 | 377 | return None |
|
368 | 378 | except OSError: |
|
369 | 379 | return None |
|
370 | 380 | |
|
371 | 381 | return lineno |
|
372 | 382 | |
|
373 | 383 | class Inspector(Colorable): |
|
374 | 384 | |
|
375 | 385 | def __init__(self, color_table=InspectColors, |
|
376 | 386 | code_color_table=PyColorize.ANSICodeColors, |
|
377 | 387 | scheme=None, |
|
378 | 388 | str_detail_level=0, |
|
379 | 389 | parent=None, config=None): |
|
380 | 390 | super(Inspector, self).__init__(parent=parent, config=config) |
|
381 | 391 | self.color_table = color_table |
|
382 | 392 | self.parser = PyColorize.Parser(out='str', parent=self, style=scheme) |
|
383 | 393 | self.format = self.parser.format |
|
384 | 394 | self.str_detail_level = str_detail_level |
|
385 | 395 | self.set_active_scheme(scheme) |
|
386 | 396 | |
|
387 | 397 | def _getdef(self,obj,oname='') -> Union[str,None]: |
|
388 | 398 | """Return the call signature for any callable object. |
|
389 | 399 | |
|
390 | 400 | If any exception is generated, None is returned instead and the |
|
391 | 401 | exception is suppressed.""" |
|
392 | 402 | try: |
|
393 | 403 | return _render_signature(signature(obj), oname) |
|
394 | 404 | except: |
|
395 | 405 | return None |
|
396 | 406 | |
|
397 | 407 | def __head(self,h) -> str: |
|
398 | 408 | """Return a header string with proper colors.""" |
|
399 | 409 | return '%s%s%s' % (self.color_table.active_colors.header,h, |
|
400 | 410 | self.color_table.active_colors.normal) |
|
401 | 411 | |
|
402 | 412 | def set_active_scheme(self, scheme): |
|
403 | 413 | if scheme is not None: |
|
404 | 414 | self.color_table.set_active_scheme(scheme) |
|
405 | 415 | self.parser.color_table.set_active_scheme(scheme) |
|
406 | 416 | |
|
407 | 417 | def noinfo(self, msg, oname): |
|
408 | 418 | """Generic message when no information is found.""" |
|
409 | 419 | print('No %s found' % msg, end=' ') |
|
410 | 420 | if oname: |
|
411 | 421 | print('for %s' % oname) |
|
412 | 422 | else: |
|
413 | 423 | print() |
|
414 | 424 | |
|
415 | 425 | def pdef(self, obj, oname=''): |
|
416 | 426 | """Print the call signature for any callable object. |
|
417 | 427 | |
|
418 | 428 | If the object is a class, print the constructor information.""" |
|
419 | 429 | |
|
420 | 430 | if not callable(obj): |
|
421 | 431 | print('Object is not callable.') |
|
422 | 432 | return |
|
423 | 433 | |
|
424 | 434 | header = '' |
|
425 | 435 | |
|
426 | 436 | if inspect.isclass(obj): |
|
427 | 437 | header = self.__head('Class constructor information:\n') |
|
428 | 438 | |
|
429 | 439 | |
|
430 | 440 | output = self._getdef(obj,oname) |
|
431 | 441 | if output is None: |
|
432 | 442 | self.noinfo('definition header',oname) |
|
433 | 443 | else: |
|
434 | 444 | print(header,self.format(output), end=' ') |
|
435 | 445 | |
|
436 | 446 | # In Python 3, all classes are new-style, so they all have __init__. |
|
437 | 447 | @skip_doctest |
|
438 | 448 | def pdoc(self, obj, oname='', formatter=None): |
|
439 | 449 | """Print the docstring for any object. |
|
440 | 450 | |
|
441 | 451 | Optional: |
|
442 | 452 | -formatter: a function to run the docstring through for specially |
|
443 | 453 | formatted docstrings. |
|
444 | 454 | |
|
445 | 455 | Examples |
|
446 | 456 | -------- |
|
447 | 457 | In [1]: class NoInit: |
|
448 | 458 | ...: pass |
|
449 | 459 | |
|
450 | 460 | In [2]: class NoDoc: |
|
451 | 461 | ...: def __init__(self): |
|
452 | 462 | ...: pass |
|
453 | 463 | |
|
454 | 464 | In [3]: %pdoc NoDoc |
|
455 | 465 | No documentation found for NoDoc |
|
456 | 466 | |
|
457 | 467 | In [4]: %pdoc NoInit |
|
458 | 468 | No documentation found for NoInit |
|
459 | 469 | |
|
460 | 470 | In [5]: obj = NoInit() |
|
461 | 471 | |
|
462 | 472 | In [6]: %pdoc obj |
|
463 | 473 | No documentation found for obj |
|
464 | 474 | |
|
465 | 475 | In [5]: obj2 = NoDoc() |
|
466 | 476 | |
|
467 | 477 | In [6]: %pdoc obj2 |
|
468 | 478 | No documentation found for obj2 |
|
469 | 479 | """ |
|
470 | 480 | |
|
471 | 481 | head = self.__head # For convenience |
|
472 | 482 | lines = [] |
|
473 | 483 | ds = getdoc(obj) |
|
474 | 484 | if formatter: |
|
475 | 485 | ds = formatter(ds).get('plain/text', ds) |
|
476 | 486 | if ds: |
|
477 | 487 | lines.append(head("Class docstring:")) |
|
478 | 488 | lines.append(indent(ds)) |
|
479 | 489 | if inspect.isclass(obj) and hasattr(obj, '__init__'): |
|
480 | 490 | init_ds = getdoc(obj.__init__) |
|
481 | 491 | if init_ds is not None: |
|
482 | 492 | lines.append(head("Init docstring:")) |
|
483 | 493 | lines.append(indent(init_ds)) |
|
484 | 494 | elif hasattr(obj,'__call__'): |
|
485 | 495 | call_ds = getdoc(obj.__call__) |
|
486 | 496 | if call_ds: |
|
487 | 497 | lines.append(head("Call docstring:")) |
|
488 | 498 | lines.append(indent(call_ds)) |
|
489 | 499 | |
|
490 | 500 | if not lines: |
|
491 | 501 | self.noinfo('documentation',oname) |
|
492 | 502 | else: |
|
493 | 503 | page.page('\n'.join(lines)) |
|
494 | 504 | |
|
495 | 505 | def psource(self, obj, oname=''): |
|
496 | 506 | """Print the source code for an object.""" |
|
497 | 507 | |
|
498 | 508 | # Flush the source cache because inspect can return out-of-date source |
|
499 | 509 | linecache.checkcache() |
|
500 | 510 | try: |
|
501 | 511 | src = getsource(obj, oname=oname) |
|
502 | 512 | except Exception: |
|
503 | 513 | src = None |
|
504 | 514 | |
|
505 | 515 | if src is None: |
|
506 | 516 | self.noinfo('source', oname) |
|
507 | 517 | else: |
|
508 | 518 | page.page(self.format(src)) |
|
509 | 519 | |
|
510 | 520 | def pfile(self, obj, oname=''): |
|
511 | 521 | """Show the whole file where an object was defined.""" |
|
512 | 522 | |
|
513 | 523 | lineno = find_source_lines(obj) |
|
514 | 524 | if lineno is None: |
|
515 | 525 | self.noinfo('file', oname) |
|
516 | 526 | return |
|
517 | 527 | |
|
518 | 528 | ofile = find_file(obj) |
|
519 | 529 | # run contents of file through pager starting at line where the object |
|
520 | 530 | # is defined, as long as the file isn't binary and is actually on the |
|
521 | 531 | # filesystem. |
|
522 | 532 | if ofile.endswith(('.so', '.dll', '.pyd')): |
|
523 | 533 | print('File %r is binary, not printing.' % ofile) |
|
524 | 534 | elif not os.path.isfile(ofile): |
|
525 | 535 | print('File %r does not exist, not printing.' % ofile) |
|
526 | 536 | else: |
|
527 | 537 | # Print only text files, not extension binaries. Note that |
|
528 | 538 | # getsourcelines returns lineno with 1-offset and page() uses |
|
529 | 539 | # 0-offset, so we must adjust. |
|
530 | 540 | page.page(self.format(openpy.read_py_file(ofile, skip_encoding_cookie=False)), lineno - 1) |
|
531 | 541 | |
|
532 | 542 | |
|
533 | 543 | def _mime_format(self, text:str, formatter=None) -> dict: |
|
534 | 544 | """Return a mime bundle representation of the input text. |
|
535 | 545 | |
|
536 | 546 | - if `formatter` is None, the returned mime bundle has |
|
537 | 547 | a ``text/plain`` field, with the input text. |
|
538 | 548 | a ``text/html`` field with a ``<pre>`` tag containing the input text. |
|
539 | 549 | |
|
540 | 550 | - if ``formatter`` is not None, it must be a callable transforming the |
|
541 | 551 | input text into a mime bundle. Default values for ``text/plain`` and |
|
542 | 552 | ``text/html`` representations are the ones described above. |
|
543 | 553 | |
|
544 | 554 | Note: |
|
545 | 555 | |
|
546 | 556 | Formatters returning strings are supported but this behavior is deprecated. |
|
547 | 557 | |
|
548 | 558 | """ |
|
549 | 559 | defaults = { |
|
550 | 560 | "text/plain": text, |
|
551 | 561 | "text/html": f"<pre>{html.escape(text)}</pre>", |
|
552 | 562 | } |
|
553 | 563 | |
|
554 | 564 | if formatter is None: |
|
555 | 565 | return defaults |
|
556 | 566 | else: |
|
557 | 567 | formatted = formatter(text) |
|
558 | 568 | |
|
559 | 569 | if not isinstance(formatted, dict): |
|
560 | 570 | # Handle the deprecated behavior of a formatter returning |
|
561 | 571 | # a string instead of a mime bundle. |
|
562 | 572 | return {"text/plain": formatted, "text/html": f"<pre>{formatted}</pre>"} |
|
563 | 573 | |
|
564 | 574 | else: |
|
565 | 575 | return dict(defaults, **formatted) |
|
566 | 576 | |
|
567 | ||
|
568 | def format_mime(self, bundle): | |
|
577 | def format_mime(self, bundle: UnformattedBundle) -> Bundle: | |
|
569 | 578 | """Format a mimebundle being created by _make_info_unformatted into a real mimebundle""" |
|
570 | 579 | # Format text/plain mimetype |
|
571 |
|
|
|
572 | # bundle['text/plain'] is a list of (head, formatted body) pairs | |
|
573 | lines = [] | |
|
574 | _len = max(len(h) for h, _ in bundle["text/plain"]) | |
|
575 | ||
|
576 | for head, body in bundle["text/plain"]: | |
|
577 | body = body.strip("\n") | |
|
578 | delim = "\n" if "\n" in body else " " | |
|
579 | lines.append( | |
|
580 | f"{self.__head(head+':')}{(_len - len(head))*' '}{delim}{body}" | |
|
581 | ) | |
|
580 | assert isinstance(bundle["text/plain"], list) | |
|
581 | for item in bundle["text/plain"]: | |
|
582 | assert isinstance(item, tuple) | |
|
582 | 583 | |
|
583 | bundle["text/plain"] = "\n".join(lines) | |
|
584 | new_b: Bundle = {} | |
|
585 | lines = [] | |
|
586 | _len = max(len(h) for h, _ in bundle["text/plain"]) | |
|
584 | 587 | |
|
585 | # Format the text/html mimetype | |
|
586 | if isinstance(bundle["text/html"], (list, tuple)): | |
|
587 | # bundle['text/html'] is a list of (head, formatted body) pairs | |
|
588 | bundle["text/html"] = "\n".join( | |
|
589 | (f"<h1>{head}</h1>\n{body}" for (head, body) in bundle["text/html"]) | |
|
588 | for head, body in bundle["text/plain"]: | |
|
589 | body = body.strip("\n") | |
|
590 | delim = "\n" if "\n" in body else " " | |
|
591 | lines.append( | |
|
592 | f"{self.__head(head+':')}{(_len - len(head))*' '}{delim}{body}" | |
|
590 | 593 | ) |
|
591 | return bundle | |
|
594 | ||
|
595 | new_b["text/plain"] = "\n".join(lines) | |
|
596 | ||
|
597 | if "text/html" in bundle: | |
|
598 | assert isinstance(bundle["text/html"], list) | |
|
599 | for item in bundle["text/html"]: | |
|
600 | assert isinstance(item, tuple) | |
|
601 | # Format the text/html mimetype | |
|
602 | if isinstance(bundle["text/html"], (list, tuple)): | |
|
603 | # bundle['text/html'] is a list of (head, formatted body) pairs | |
|
604 | new_b["text/html"] = "\n".join( | |
|
605 | (f"<h1>{head}</h1>\n{body}" for (head, body) in bundle["text/html"]) | |
|
606 | ) | |
|
607 | ||
|
608 | for k in bundle.keys(): | |
|
609 | if k in ("text/html", "text/plain"): | |
|
610 | continue | |
|
611 | else: | |
|
612 | new_b = bundle[k] # type:ignore | |
|
613 | return new_b | |
|
592 | 614 | |
|
593 | 615 | def _append_info_field( |
|
594 | self, bundle, title: str, key: str, info, omit_sections, formatter | |
|
616 | self, | |
|
617 | bundle: UnformattedBundle, | |
|
618 | title: str, | |
|
619 | key: str, | |
|
620 | info, | |
|
621 | omit_sections, | |
|
622 | formatter, | |
|
595 | 623 | ): |
|
596 | 624 | """Append an info value to the unformatted mimebundle being constructed by _make_info_unformatted""" |
|
597 | 625 | if title in omit_sections or key in omit_sections: |
|
598 | 626 | return |
|
599 | 627 | field = info[key] |
|
600 | 628 | if field is not None: |
|
601 | 629 | formatted_field = self._mime_format(field, formatter) |
|
602 | 630 | bundle["text/plain"].append((title, formatted_field["text/plain"])) |
|
603 | 631 | bundle["text/html"].append((title, formatted_field["text/html"])) |
|
604 | 632 | |
|
605 | def _make_info_unformatted(self, obj, info, formatter, detail_level, omit_sections): | |
|
633 | def _make_info_unformatted( | |
|
634 | self, obj, info, formatter, detail_level, omit_sections | |
|
635 | ) -> UnformattedBundle: | |
|
606 | 636 | """Assemble the mimebundle as unformatted lists of information""" |
|
607 | bundle = { | |
|
637 | bundle: UnformattedBundle = { | |
|
608 | 638 | "text/plain": [], |
|
609 | 639 | "text/html": [], |
|
610 | 640 | } |
|
611 | 641 | |
|
612 | 642 | # A convenience function to simplify calls below |
|
613 | def append_field(bundle, title: str, key: str, formatter=None): | |
|
643 | def append_field( | |
|
644 | bundle: UnformattedBundle, title: str, key: str, formatter=None | |
|
645 | ): | |
|
614 | 646 | self._append_info_field( |
|
615 | 647 | bundle, |
|
616 | 648 | title=title, |
|
617 | 649 | key=key, |
|
618 | 650 | info=info, |
|
619 | 651 | omit_sections=omit_sections, |
|
620 | 652 | formatter=formatter, |
|
621 | 653 | ) |
|
622 | 654 | |
|
623 | def code_formatter(text): | |
|
655 | def code_formatter(text) -> Bundle: | |
|
624 | 656 | return { |
|
625 | 657 | 'text/plain': self.format(text), |
|
626 | 658 | 'text/html': pylight(text) |
|
627 | 659 | } |
|
628 | 660 | |
|
629 | 661 | if info["isalias"]: |
|
630 | 662 | append_field(bundle, "Repr", "string_form") |
|
631 | 663 | |
|
632 | 664 | elif info['ismagic']: |
|
633 | 665 | if detail_level > 0: |
|
634 | 666 | append_field(bundle, "Source", "source", code_formatter) |
|
635 | 667 | else: |
|
636 | 668 | append_field(bundle, "Docstring", "docstring", formatter) |
|
637 | 669 | append_field(bundle, "File", "file") |
|
638 | 670 | |
|
639 | 671 | elif info['isclass'] or is_simple_callable(obj): |
|
640 | 672 | # Functions, methods, classes |
|
641 | 673 | append_field(bundle, "Signature", "definition", code_formatter) |
|
642 | 674 | append_field(bundle, "Init signature", "init_definition", code_formatter) |
|
643 | 675 | append_field(bundle, "Docstring", "docstring", formatter) |
|
644 | 676 | if detail_level > 0 and info["source"]: |
|
645 | 677 | append_field(bundle, "Source", "source", code_formatter) |
|
646 | 678 | else: |
|
647 | 679 | append_field(bundle, "Init docstring", "init_docstring", formatter) |
|
648 | 680 | |
|
649 | 681 | append_field(bundle, "File", "file") |
|
650 | 682 | append_field(bundle, "Type", "type_name") |
|
651 | 683 | append_field(bundle, "Subclasses", "subclasses") |
|
652 | 684 | |
|
653 | 685 | else: |
|
654 | 686 | # General Python objects |
|
655 | 687 | append_field(bundle, "Signature", "definition", code_formatter) |
|
656 | 688 | append_field(bundle, "Call signature", "call_def", code_formatter) |
|
657 | 689 | append_field(bundle, "Type", "type_name") |
|
658 | 690 | append_field(bundle, "String form", "string_form") |
|
659 | 691 | |
|
660 | 692 | # Namespace |
|
661 | 693 | if info["namespace"] != "Interactive": |
|
662 | 694 | append_field(bundle, "Namespace", "namespace") |
|
663 | 695 | |
|
664 | 696 | append_field(bundle, "Length", "length") |
|
665 | 697 | append_field(bundle, "File", "file") |
|
666 | 698 | |
|
667 | 699 | # Source or docstring, depending on detail level and whether |
|
668 | 700 | # source found. |
|
669 | 701 | if detail_level > 0 and info["source"]: |
|
670 | 702 | append_field(bundle, "Source", "source", code_formatter) |
|
671 | 703 | else: |
|
672 | 704 | append_field(bundle, "Docstring", "docstring", formatter) |
|
673 | 705 | |
|
674 | 706 | append_field(bundle, "Class docstring", "class_docstring", formatter) |
|
675 | 707 | append_field(bundle, "Init docstring", "init_docstring", formatter) |
|
676 | 708 | append_field(bundle, "Call docstring", "call_docstring", formatter) |
|
677 | 709 | return bundle |
|
678 | 710 | |
|
679 | 711 | |
|
680 | 712 | def _get_info( |
|
681 | self, obj, oname="", formatter=None, info=None, detail_level=0, omit_sections=() | |
|
682 | ): | |
|
713 | self, | |
|
714 | obj: Any, | |
|
715 | oname: str = "", | |
|
716 | formatter=None, | |
|
717 | info: Optional[OInfo] = None, | |
|
718 | detail_level=0, | |
|
719 | omit_sections=(), | |
|
720 | ) -> Bundle: | |
|
683 | 721 | """Retrieve an info dict and format it. |
|
684 | 722 | |
|
685 | 723 | Parameters |
|
686 | 724 | ---------- |
|
687 | 725 | obj : any |
|
688 | 726 | Object to inspect and return info from |
|
689 | 727 | oname : str (default: ''): |
|
690 | 728 | Name of the variable pointing to `obj`. |
|
691 | 729 | formatter : callable |
|
692 | 730 | info |
|
693 | 731 | already computed information |
|
694 | 732 | detail_level : integer |
|
695 | 733 | Granularity of detail level, if set to 1, give more information. |
|
696 | 734 | omit_sections : container[str] |
|
697 | 735 | Titles or keys to omit from output (can be set, tuple, etc., anything supporting `in`) |
|
698 | 736 | """ |
|
699 | 737 | |
|
700 | info = self.info(obj, oname=oname, info=info, detail_level=detail_level) | |
|
738 | info_dict = self.info(obj, oname=oname, info=info, detail_level=detail_level) | |
|
701 | 739 | bundle = self._make_info_unformatted( |
|
702 | obj, info, formatter, detail_level=detail_level, omit_sections=omit_sections | |
|
740 | obj, | |
|
741 | info_dict, | |
|
742 | formatter, | |
|
743 | detail_level=detail_level, | |
|
744 | omit_sections=omit_sections, | |
|
703 | 745 | ) |
|
704 | 746 | return self.format_mime(bundle) |
|
705 | 747 | |
|
706 | 748 | def pinfo( |
|
707 | 749 | self, |
|
708 | 750 | obj, |
|
709 | 751 | oname="", |
|
710 | 752 | formatter=None, |
|
711 | info=None, | |
|
753 | info: Optional[OInfo] = None, | |
|
712 | 754 | detail_level=0, |
|
713 | 755 | enable_html_pager=True, |
|
714 | 756 | omit_sections=(), |
|
715 | 757 | ): |
|
716 | 758 | """Show detailed information about an object. |
|
717 | 759 | |
|
718 | 760 | Optional arguments: |
|
719 | 761 | |
|
720 | 762 | - oname: name of the variable pointing to the object. |
|
721 | 763 | |
|
722 | 764 | - formatter: callable (optional) |
|
723 | 765 | A special formatter for docstrings. |
|
724 | 766 | |
|
725 | 767 | The formatter is a callable that takes a string as an input |
|
726 | 768 | and returns either a formatted string or a mime type bundle |
|
727 | 769 | in the form of a dictionary. |
|
728 | 770 | |
|
729 | 771 | Although the support of custom formatter returning a string |
|
730 | 772 | instead of a mime type bundle is deprecated. |
|
731 | 773 | |
|
732 | 774 | - info: a structure with some information fields which may have been |
|
733 | 775 | precomputed already. |
|
734 | 776 | |
|
735 | 777 | - detail_level: if set to 1, more information is given. |
|
736 | 778 | |
|
737 | 779 | - omit_sections: set of section keys and titles to omit |
|
738 | 780 | """ |
|
739 | info = self._get_info( | |
|
781 | assert info is not None | |
|
782 | info_b: Bundle = self._get_info( | |
|
740 | 783 | obj, oname, formatter, info, detail_level, omit_sections=omit_sections |
|
741 | 784 | ) |
|
742 | 785 | if not enable_html_pager: |
|
743 |
del info[ |
|
|
744 | page.page(info) | |
|
786 | del info_b["text/html"] | |
|
787 | page.page(info_b) | |
|
745 | 788 | |
|
746 | 789 | def _info(self, obj, oname="", info=None, detail_level=0): |
|
747 | 790 | """ |
|
748 | 791 | Inspector.info() was likely improperly marked as deprecated |
|
749 | 792 | while only a parameter was deprecated. We "un-deprecate" it. |
|
750 | 793 | """ |
|
751 | 794 | |
|
752 | 795 | warnings.warn( |
|
753 | 796 | "The `Inspector.info()` method has been un-deprecated as of 8.0 " |
|
754 | 797 | "and the `formatter=` keyword removed. `Inspector._info` is now " |
|
755 | 798 | "an alias, and you can just call `.info()` directly.", |
|
756 | 799 | DeprecationWarning, |
|
757 | 800 | stacklevel=2, |
|
758 | 801 | ) |
|
759 | 802 | return self.info(obj, oname=oname, info=info, detail_level=detail_level) |
|
760 | 803 | |
|
761 |
def info(self, obj, oname="", info=None, detail_level=0) -> |
|
|
804 | def info(self, obj, oname="", info=None, detail_level=0) -> Dict[str, Any]: | |
|
762 | 805 | """Compute a dict with detailed information about an object. |
|
763 | 806 | |
|
764 | 807 | Parameters |
|
765 | 808 | ---------- |
|
766 | 809 | obj : any |
|
767 | 810 | An object to find information about |
|
768 | 811 | oname : str (default: '') |
|
769 | 812 | Name of the variable pointing to `obj`. |
|
770 | 813 | info : (default: None) |
|
771 | 814 | A struct (dict like with attr access) with some information fields |
|
772 | 815 | which may have been precomputed already. |
|
773 | 816 | detail_level : int (default:0) |
|
774 | 817 | If set to 1, more information is given. |
|
775 | 818 | |
|
776 | 819 | Returns |
|
777 | 820 | ------- |
|
778 | 821 | An object info dict with known fields from `info_fields`. Keys are |
|
779 | 822 | strings, values are string or None. |
|
780 | 823 | """ |
|
781 | 824 | |
|
782 | 825 | if info is None: |
|
783 | 826 | ismagic = False |
|
784 | 827 | isalias = False |
|
785 | 828 | ospace = '' |
|
786 | 829 | else: |
|
787 | 830 | ismagic = info.ismagic |
|
788 | 831 | isalias = info.isalias |
|
789 | 832 | ospace = info.namespace |
|
790 | 833 | |
|
791 | 834 | # Get docstring, special-casing aliases: |
|
792 | if isalias: | |
|
835 | att_name = oname.split(".")[-1] | |
|
836 | parents_docs = None | |
|
837 | prelude = "" | |
|
838 | if info and info.parent and hasattr(info.parent, HOOK_NAME): | |
|
839 | parents_docs_dict = getattr(info.parent, HOOK_NAME) | |
|
840 | parents_docs = parents_docs_dict.get(att_name, None) | |
|
841 | out = dict( | |
|
842 | name=oname, found=True, isalias=isalias, ismagic=ismagic, subclasses=None | |
|
843 | ) | |
|
844 | ||
|
845 | if parents_docs: | |
|
846 | ds = parents_docs | |
|
847 | elif isalias: | |
|
793 | 848 | if not callable(obj): |
|
794 | 849 | try: |
|
795 | 850 | ds = "Alias to the system command:\n %s" % obj[1] |
|
796 | 851 | except: |
|
797 | 852 | ds = "Alias: " + str(obj) |
|
798 | 853 | else: |
|
799 | 854 | ds = "Alias to " + str(obj) |
|
800 | 855 | if obj.__doc__: |
|
801 | 856 | ds += "\nDocstring:\n" + obj.__doc__ |
|
802 | 857 | else: |
|
803 | 858 | ds_or_None = getdoc(obj) |
|
804 | 859 | if ds_or_None is None: |
|
805 | 860 | ds = '<no docstring>' |
|
806 | 861 | else: |
|
807 | 862 | ds = ds_or_None |
|
808 | 863 | |
|
864 | ds = prelude + ds | |
|
865 | ||
|
809 | 866 | # store output in a dict, we initialize it here and fill it as we go |
|
810 | out = dict(name=oname, found=True, isalias=isalias, ismagic=ismagic, subclasses=None) | |
|
811 | 867 | |
|
812 | 868 | string_max = 200 # max size of strings to show (snipped if longer) |
|
813 | 869 | shalf = int((string_max - 5) / 2) |
|
814 | 870 | |
|
815 | 871 | if ismagic: |
|
816 | 872 | out['type_name'] = 'Magic function' |
|
817 | 873 | elif isalias: |
|
818 | 874 | out['type_name'] = 'System alias' |
|
819 | 875 | else: |
|
820 | 876 | out['type_name'] = type(obj).__name__ |
|
821 | 877 | |
|
822 | 878 | try: |
|
823 | 879 | bclass = obj.__class__ |
|
824 | 880 | out['base_class'] = str(bclass) |
|
825 | 881 | except: |
|
826 | 882 | pass |
|
827 | 883 | |
|
828 | 884 | # String form, but snip if too long in ? form (full in ??) |
|
829 | 885 | if detail_level >= self.str_detail_level: |
|
830 | 886 | try: |
|
831 | 887 | ostr = str(obj) |
|
832 | 888 | str_head = 'string_form' |
|
833 | 889 | if not detail_level and len(ostr)>string_max: |
|
834 | 890 | ostr = ostr[:shalf] + ' <...> ' + ostr[-shalf:] |
|
835 | 891 | ostr = ("\n" + " " * len(str_head.expandtabs())).\ |
|
836 | 892 | join(q.strip() for q in ostr.split("\n")) |
|
837 | 893 | out[str_head] = ostr |
|
838 | 894 | except: |
|
839 | 895 | pass |
|
840 | 896 | |
|
841 | 897 | if ospace: |
|
842 | 898 | out['namespace'] = ospace |
|
843 | 899 | |
|
844 | 900 | # Length (for strings and lists) |
|
845 | 901 | try: |
|
846 | 902 | out['length'] = str(len(obj)) |
|
847 | 903 | except Exception: |
|
848 | 904 | pass |
|
849 | 905 | |
|
850 | 906 | # Filename where object was defined |
|
851 | 907 | binary_file = False |
|
852 | 908 | fname = find_file(obj) |
|
853 | 909 | if fname is None: |
|
854 | 910 | # if anything goes wrong, we don't want to show source, so it's as |
|
855 | 911 | # if the file was binary |
|
856 | 912 | binary_file = True |
|
857 | 913 | else: |
|
858 | 914 | if fname.endswith(('.so', '.dll', '.pyd')): |
|
859 | 915 | binary_file = True |
|
860 | 916 | elif fname.endswith('<string>'): |
|
861 | 917 | fname = 'Dynamically generated function. No source code available.' |
|
862 | 918 | out['file'] = compress_user(fname) |
|
863 | 919 | |
|
864 | 920 | # Original source code for a callable, class or property. |
|
865 | 921 | if detail_level: |
|
866 | 922 | # Flush the source cache because inspect can return out-of-date |
|
867 | 923 | # source |
|
868 | 924 | linecache.checkcache() |
|
869 | 925 | try: |
|
870 | 926 | if isinstance(obj, property) or not binary_file: |
|
871 | 927 | src = getsource(obj, oname) |
|
872 | 928 | if src is not None: |
|
873 | 929 | src = src.rstrip() |
|
874 | 930 | out['source'] = src |
|
875 | 931 | |
|
876 | 932 | except Exception: |
|
877 | 933 | pass |
|
878 | 934 | |
|
879 | 935 | # Add docstring only if no source is to be shown (avoid repetitions). |
|
880 | 936 | if ds and not self._source_contains_docstring(out.get('source'), ds): |
|
881 | 937 | out['docstring'] = ds |
|
882 | 938 | |
|
883 | 939 | # Constructor docstring for classes |
|
884 | 940 | if inspect.isclass(obj): |
|
885 | 941 | out['isclass'] = True |
|
886 | 942 | |
|
887 | 943 | # get the init signature: |
|
888 | 944 | try: |
|
889 | 945 | init_def = self._getdef(obj, oname) |
|
890 | 946 | except AttributeError: |
|
891 | 947 | init_def = None |
|
892 | 948 | |
|
893 | 949 | # get the __init__ docstring |
|
894 | 950 | try: |
|
895 | 951 | obj_init = obj.__init__ |
|
896 | 952 | except AttributeError: |
|
897 | 953 | init_ds = None |
|
898 | 954 | else: |
|
899 | 955 | if init_def is None: |
|
900 | 956 | # Get signature from init if top-level sig failed. |
|
901 | 957 | # Can happen for built-in types (list, etc.). |
|
902 | 958 | try: |
|
903 | 959 | init_def = self._getdef(obj_init, oname) |
|
904 | 960 | except AttributeError: |
|
905 | 961 | pass |
|
906 | 962 | init_ds = getdoc(obj_init) |
|
907 | 963 | # Skip Python's auto-generated docstrings |
|
908 | 964 | if init_ds == _object_init_docstring: |
|
909 | 965 | init_ds = None |
|
910 | 966 | |
|
911 | 967 | if init_def: |
|
912 | 968 | out['init_definition'] = init_def |
|
913 | 969 | |
|
914 | 970 | if init_ds: |
|
915 | 971 | out['init_docstring'] = init_ds |
|
916 | 972 | |
|
917 | 973 | names = [sub.__name__ for sub in type.__subclasses__(obj)] |
|
918 | 974 | if len(names) < 10: |
|
919 | 975 | all_names = ', '.join(names) |
|
920 | 976 | else: |
|
921 | 977 | all_names = ', '.join(names[:10]+['...']) |
|
922 | 978 | out['subclasses'] = all_names |
|
923 | 979 | # and class docstring for instances: |
|
924 | 980 | else: |
|
925 | 981 | # reconstruct the function definition and print it: |
|
926 | 982 | defln = self._getdef(obj, oname) |
|
927 | 983 | if defln: |
|
928 | 984 | out['definition'] = defln |
|
929 | 985 | |
|
930 | 986 | # First, check whether the instance docstring is identical to the |
|
931 | 987 | # class one, and print it separately if they don't coincide. In |
|
932 | 988 | # most cases they will, but it's nice to print all the info for |
|
933 | 989 | # objects which use instance-customized docstrings. |
|
934 | 990 | if ds: |
|
935 | 991 | try: |
|
936 | 992 | cls = getattr(obj,'__class__') |
|
937 | 993 | except: |
|
938 | 994 | class_ds = None |
|
939 | 995 | else: |
|
940 | 996 | class_ds = getdoc(cls) |
|
941 | 997 | # Skip Python's auto-generated docstrings |
|
942 | 998 | if class_ds in _builtin_type_docstrings: |
|
943 | 999 | class_ds = None |
|
944 | 1000 | if class_ds and ds != class_ds: |
|
945 | 1001 | out['class_docstring'] = class_ds |
|
946 | 1002 | |
|
947 | 1003 | # Next, try to show constructor docstrings |
|
948 | 1004 | try: |
|
949 | 1005 | init_ds = getdoc(obj.__init__) |
|
950 | 1006 | # Skip Python's auto-generated docstrings |
|
951 | 1007 | if init_ds == _object_init_docstring: |
|
952 | 1008 | init_ds = None |
|
953 | 1009 | except AttributeError: |
|
954 | 1010 | init_ds = None |
|
955 | 1011 | if init_ds: |
|
956 | 1012 | out['init_docstring'] = init_ds |
|
957 | 1013 | |
|
958 | 1014 | # Call form docstring for callable instances |
|
959 | 1015 | if safe_hasattr(obj, '__call__') and not is_simple_callable(obj): |
|
960 | 1016 | call_def = self._getdef(obj.__call__, oname) |
|
961 | 1017 | if call_def and (call_def != out.get('definition')): |
|
962 | 1018 | # it may never be the case that call def and definition differ, |
|
963 | 1019 | # but don't include the same signature twice |
|
964 | 1020 | out['call_def'] = call_def |
|
965 | 1021 | call_ds = getdoc(obj.__call__) |
|
966 | 1022 | # Skip Python's auto-generated docstrings |
|
967 | 1023 | if call_ds == _func_call_docstring: |
|
968 | 1024 | call_ds = None |
|
969 | 1025 | if call_ds: |
|
970 | 1026 | out['call_docstring'] = call_ds |
|
971 | 1027 | |
|
972 | 1028 | return object_info(**out) |
|
973 | 1029 | |
|
974 | 1030 | @staticmethod |
|
975 | 1031 | def _source_contains_docstring(src, doc): |
|
976 | 1032 | """ |
|
977 | 1033 | Check whether the source *src* contains the docstring *doc*. |
|
978 | 1034 | |
|
979 | 1035 | This is is helper function to skip displaying the docstring if the |
|
980 | 1036 | source already contains it, avoiding repetition of information. |
|
981 | 1037 | """ |
|
982 | 1038 | try: |
|
983 | def_node, = ast.parse(dedent(src)).body | |
|
984 | return ast.get_docstring(def_node) == doc | |
|
1039 | (def_node,) = ast.parse(dedent(src)).body | |
|
1040 | return ast.get_docstring(def_node) == doc # type: ignore[arg-type] | |
|
985 | 1041 | except Exception: |
|
986 | 1042 | # The source can become invalid or even non-existent (because it |
|
987 | 1043 | # is re-fetched from the source file) so the above code fail in |
|
988 | 1044 | # arbitrary ways. |
|
989 | 1045 | return False |
|
990 | 1046 | |
|
991 | 1047 | def psearch(self,pattern,ns_table,ns_search=[], |
|
992 | 1048 | ignore_case=False,show_all=False, *, list_types=False): |
|
993 | 1049 | """Search namespaces with wildcards for objects. |
|
994 | 1050 | |
|
995 | 1051 | Arguments: |
|
996 | 1052 | |
|
997 | 1053 | - pattern: string containing shell-like wildcards to use in namespace |
|
998 | 1054 | searches and optionally a type specification to narrow the search to |
|
999 | 1055 | objects of that type. |
|
1000 | 1056 | |
|
1001 | 1057 | - ns_table: dict of name->namespaces for search. |
|
1002 | 1058 | |
|
1003 | 1059 | Optional arguments: |
|
1004 | 1060 | |
|
1005 | 1061 | - ns_search: list of namespace names to include in search. |
|
1006 | 1062 | |
|
1007 | 1063 | - ignore_case(False): make the search case-insensitive. |
|
1008 | 1064 | |
|
1009 | 1065 | - show_all(False): show all names, including those starting with |
|
1010 | 1066 | underscores. |
|
1011 | 1067 | |
|
1012 | 1068 | - list_types(False): list all available object types for object matching. |
|
1013 | 1069 | """ |
|
1014 | 1070 | #print 'ps pattern:<%r>' % pattern # dbg |
|
1015 | 1071 | |
|
1016 | 1072 | # defaults |
|
1017 | 1073 | type_pattern = 'all' |
|
1018 | 1074 | filter = '' |
|
1019 | 1075 | |
|
1020 | 1076 | # list all object types |
|
1021 | 1077 | if list_types: |
|
1022 | 1078 | page.page('\n'.join(sorted(typestr2type))) |
|
1023 | 1079 | return |
|
1024 | 1080 | |
|
1025 | 1081 | cmds = pattern.split() |
|
1026 | 1082 | len_cmds = len(cmds) |
|
1027 | 1083 | if len_cmds == 1: |
|
1028 | 1084 | # Only filter pattern given |
|
1029 | 1085 | filter = cmds[0] |
|
1030 | 1086 | elif len_cmds == 2: |
|
1031 | 1087 | # Both filter and type specified |
|
1032 | 1088 | filter,type_pattern = cmds |
|
1033 | 1089 | else: |
|
1034 | 1090 | raise ValueError('invalid argument string for psearch: <%s>' % |
|
1035 | 1091 | pattern) |
|
1036 | 1092 | |
|
1037 | 1093 | # filter search namespaces |
|
1038 | 1094 | for name in ns_search: |
|
1039 | 1095 | if name not in ns_table: |
|
1040 | 1096 | raise ValueError('invalid namespace <%s>. Valid names: %s' % |
|
1041 | 1097 | (name,ns_table.keys())) |
|
1042 | 1098 | |
|
1043 | 1099 | #print 'type_pattern:',type_pattern # dbg |
|
1044 | 1100 | search_result, namespaces_seen = set(), set() |
|
1045 | 1101 | for ns_name in ns_search: |
|
1046 | 1102 | ns = ns_table[ns_name] |
|
1047 | 1103 | # Normally, locals and globals are the same, so we just check one. |
|
1048 | 1104 | if id(ns) in namespaces_seen: |
|
1049 | 1105 | continue |
|
1050 | 1106 | namespaces_seen.add(id(ns)) |
|
1051 | 1107 | tmp_res = list_namespace(ns, type_pattern, filter, |
|
1052 | 1108 | ignore_case=ignore_case, show_all=show_all) |
|
1053 | 1109 | search_result.update(tmp_res) |
|
1054 | 1110 | |
|
1055 | 1111 | page.page('\n'.join(sorted(search_result))) |
|
1056 | 1112 | |
|
1057 | 1113 | |
|
1058 | 1114 | def _render_signature(obj_signature, obj_name) -> str: |
|
1059 | 1115 | """ |
|
1060 | 1116 | This was mostly taken from inspect.Signature.__str__. |
|
1061 | 1117 | Look there for the comments. |
|
1062 | 1118 | The only change is to add linebreaks when this gets too long. |
|
1063 | 1119 | """ |
|
1064 | 1120 | result = [] |
|
1065 | 1121 | pos_only = False |
|
1066 | 1122 | kw_only = True |
|
1067 | 1123 | for param in obj_signature.parameters.values(): |
|
1068 | 1124 | if param.kind == inspect.Parameter.POSITIONAL_ONLY: |
|
1069 | 1125 | pos_only = True |
|
1070 | 1126 | elif pos_only: |
|
1071 | 1127 | result.append('/') |
|
1072 | 1128 | pos_only = False |
|
1073 | 1129 | |
|
1074 | 1130 | if param.kind == inspect.Parameter.VAR_POSITIONAL: |
|
1075 | 1131 | kw_only = False |
|
1076 | 1132 | elif param.kind == inspect.Parameter.KEYWORD_ONLY and kw_only: |
|
1077 | 1133 | result.append('*') |
|
1078 | 1134 | kw_only = False |
|
1079 | 1135 | |
|
1080 | 1136 | result.append(str(param)) |
|
1081 | 1137 | |
|
1082 | 1138 | if pos_only: |
|
1083 | 1139 | result.append('/') |
|
1084 | 1140 | |
|
1085 | 1141 | # add up name, parameters, braces (2), and commas |
|
1086 | 1142 | if len(obj_name) + sum(len(r) + 2 for r in result) > 75: |
|
1087 | 1143 | # This doesn’t fit behind “Signature: ” in an inspect window. |
|
1088 | 1144 | rendered = '{}(\n{})'.format(obj_name, ''.join( |
|
1089 | 1145 | ' {},\n'.format(r) for r in result) |
|
1090 | 1146 | ) |
|
1091 | 1147 | else: |
|
1092 | 1148 | rendered = '{}({})'.format(obj_name, ', '.join(result)) |
|
1093 | 1149 | |
|
1094 | 1150 | if obj_signature.return_annotation is not inspect._empty: |
|
1095 | 1151 | anno = inspect.formatannotation(obj_signature.return_annotation) |
|
1096 | 1152 | rendered += ' -> {}'.format(anno) |
|
1097 | 1153 | |
|
1098 | 1154 | return rendered |
@@ -1,541 +1,578 b'' | |||
|
1 | 1 | """Tests for the object inspection functionality. |
|
2 | 2 | """ |
|
3 | 3 | |
|
4 | 4 | # Copyright (c) IPython Development Team. |
|
5 | 5 | # Distributed under the terms of the Modified BSD License. |
|
6 | 6 | |
|
7 | 7 | |
|
8 | 8 | from contextlib import contextmanager |
|
9 | 9 | from inspect import signature, Signature, Parameter |
|
10 | 10 | import inspect |
|
11 | 11 | import os |
|
12 | 12 | import pytest |
|
13 | 13 | import re |
|
14 | 14 | import sys |
|
15 | 15 | |
|
16 | 16 | from .. import oinspect |
|
17 | 17 | |
|
18 | 18 | from decorator import decorator |
|
19 | 19 | |
|
20 | 20 | from IPython.testing.tools import AssertPrints, AssertNotPrints |
|
21 | 21 | from IPython.utils.path import compress_user |
|
22 | 22 | |
|
23 | 23 | |
|
24 | 24 | #----------------------------------------------------------------------------- |
|
25 | 25 | # Globals and constants |
|
26 | 26 | #----------------------------------------------------------------------------- |
|
27 | 27 | |
|
28 | 28 | inspector = None |
|
29 | 29 | |
|
30 | 30 | def setup_module(): |
|
31 | 31 | global inspector |
|
32 | 32 | inspector = oinspect.Inspector() |
|
33 | 33 | |
|
34 | 34 | |
|
35 | 35 | class SourceModuleMainTest: |
|
36 | 36 | __module__ = "__main__" |
|
37 | 37 | |
|
38 | 38 | |
|
39 | 39 | #----------------------------------------------------------------------------- |
|
40 | 40 | # Local utilities |
|
41 | 41 | #----------------------------------------------------------------------------- |
|
42 | 42 | |
|
43 | 43 | # WARNING: since this test checks the line number where a function is |
|
44 | 44 | # defined, if any code is inserted above, the following line will need to be |
|
45 | 45 | # updated. Do NOT insert any whitespace between the next line and the function |
|
46 | 46 | # definition below. |
|
47 | 47 | THIS_LINE_NUMBER = 47 # Put here the actual number of this line |
|
48 | 48 | |
|
49 | 49 | |
|
50 | 50 | def test_find_source_lines(): |
|
51 | 51 | assert oinspect.find_source_lines(test_find_source_lines) == THIS_LINE_NUMBER + 3 |
|
52 | 52 | assert oinspect.find_source_lines(type) is None |
|
53 | 53 | assert oinspect.find_source_lines(SourceModuleMainTest) is None |
|
54 | 54 | assert oinspect.find_source_lines(SourceModuleMainTest()) is None |
|
55 | 55 | |
|
56 | 56 | |
|
57 | 57 | def test_getsource(): |
|
58 | 58 | assert oinspect.getsource(type) is None |
|
59 | 59 | assert oinspect.getsource(SourceModuleMainTest) is None |
|
60 | 60 | assert oinspect.getsource(SourceModuleMainTest()) is None |
|
61 | 61 | |
|
62 | 62 | |
|
63 | 63 | def test_inspect_getfile_raises_exception(): |
|
64 | 64 | """Check oinspect.find_file/getsource/find_source_lines expectations""" |
|
65 | 65 | with pytest.raises(TypeError): |
|
66 | 66 | inspect.getfile(type) |
|
67 | 67 | with pytest.raises(OSError if sys.version_info >= (3, 10) else TypeError): |
|
68 | 68 | inspect.getfile(SourceModuleMainTest) |
|
69 | 69 | |
|
70 | 70 | |
|
71 | 71 | # A couple of utilities to ensure these tests work the same from a source or a |
|
72 | 72 | # binary install |
|
73 | 73 | def pyfile(fname): |
|
74 | 74 | return os.path.normcase(re.sub('.py[co]$', '.py', fname)) |
|
75 | 75 | |
|
76 | 76 | |
|
77 | 77 | def match_pyfiles(f1, f2): |
|
78 | 78 | assert pyfile(f1) == pyfile(f2) |
|
79 | 79 | |
|
80 | 80 | |
|
81 | 81 | def test_find_file(): |
|
82 | 82 | match_pyfiles(oinspect.find_file(test_find_file), os.path.abspath(__file__)) |
|
83 | 83 | assert oinspect.find_file(type) is None |
|
84 | 84 | assert oinspect.find_file(SourceModuleMainTest) is None |
|
85 | 85 | assert oinspect.find_file(SourceModuleMainTest()) is None |
|
86 | 86 | |
|
87 | 87 | |
|
88 | 88 | def test_find_file_decorated1(): |
|
89 | 89 | |
|
90 | 90 | @decorator |
|
91 | 91 | def noop1(f): |
|
92 | 92 | def wrapper(*a, **kw): |
|
93 | 93 | return f(*a, **kw) |
|
94 | 94 | return wrapper |
|
95 | 95 | |
|
96 | 96 | @noop1 |
|
97 | 97 | def f(x): |
|
98 | 98 | "My docstring" |
|
99 | 99 | |
|
100 | 100 | match_pyfiles(oinspect.find_file(f), os.path.abspath(__file__)) |
|
101 | 101 | assert f.__doc__ == "My docstring" |
|
102 | 102 | |
|
103 | 103 | |
|
104 | 104 | def test_find_file_decorated2(): |
|
105 | 105 | |
|
106 | 106 | @decorator |
|
107 | 107 | def noop2(f, *a, **kw): |
|
108 | 108 | return f(*a, **kw) |
|
109 | 109 | |
|
110 | 110 | @noop2 |
|
111 | 111 | @noop2 |
|
112 | 112 | @noop2 |
|
113 | 113 | def f(x): |
|
114 | 114 | "My docstring 2" |
|
115 | 115 | |
|
116 | 116 | match_pyfiles(oinspect.find_file(f), os.path.abspath(__file__)) |
|
117 | 117 | assert f.__doc__ == "My docstring 2" |
|
118 | 118 | |
|
119 | 119 | |
|
120 | 120 | def test_find_file_magic(): |
|
121 | 121 | run = ip.find_line_magic('run') |
|
122 | 122 | assert oinspect.find_file(run) is not None |
|
123 | 123 | |
|
124 | 124 | |
|
125 | 125 | # A few generic objects we can then inspect in the tests below |
|
126 | 126 | |
|
127 | 127 | class Call(object): |
|
128 | 128 | """This is the class docstring.""" |
|
129 | 129 | |
|
130 | 130 | def __init__(self, x, y=1): |
|
131 | 131 | """This is the constructor docstring.""" |
|
132 | 132 | |
|
133 | 133 | def __call__(self, *a, **kw): |
|
134 | 134 | """This is the call docstring.""" |
|
135 | 135 | |
|
136 | 136 | def method(self, x, z=2): |
|
137 | 137 | """Some method's docstring""" |
|
138 | 138 | |
|
139 | 139 | class HasSignature(object): |
|
140 | 140 | """This is the class docstring.""" |
|
141 | 141 | __signature__ = Signature([Parameter('test', Parameter.POSITIONAL_OR_KEYWORD)]) |
|
142 | 142 | |
|
143 | 143 | def __init__(self, *args): |
|
144 | 144 | """This is the init docstring""" |
|
145 | 145 | |
|
146 | 146 | |
|
147 | 147 | class SimpleClass(object): |
|
148 | 148 | def method(self, x, z=2): |
|
149 | 149 | """Some method's docstring""" |
|
150 | 150 | |
|
151 | 151 | |
|
152 | 152 | class Awkward(object): |
|
153 | 153 | def __getattr__(self, name): |
|
154 | 154 | raise Exception(name) |
|
155 | 155 | |
|
156 | 156 | class NoBoolCall: |
|
157 | 157 | """ |
|
158 | 158 | callable with `__bool__` raising should still be inspect-able. |
|
159 | 159 | """ |
|
160 | 160 | |
|
161 | 161 | def __call__(self): |
|
162 | 162 | """does nothing""" |
|
163 | 163 | pass |
|
164 | 164 | |
|
165 | 165 | def __bool__(self): |
|
166 | 166 | """just raise NotImplemented""" |
|
167 | 167 | raise NotImplementedError('Must be implemented') |
|
168 | 168 | |
|
169 | 169 | |
|
170 | 170 | class SerialLiar(object): |
|
171 | 171 | """Attribute accesses always get another copy of the same class. |
|
172 | 172 | |
|
173 | 173 | unittest.mock.call does something similar, but it's not ideal for testing |
|
174 | 174 | as the failure mode is to eat all your RAM. This gives up after 10k levels. |
|
175 | 175 | """ |
|
176 | 176 | def __init__(self, max_fibbing_twig, lies_told=0): |
|
177 | 177 | if lies_told > 10000: |
|
178 | 178 | raise RuntimeError('Nose too long, honesty is the best policy') |
|
179 | 179 | self.max_fibbing_twig = max_fibbing_twig |
|
180 | 180 | self.lies_told = lies_told |
|
181 | 181 | max_fibbing_twig[0] = max(max_fibbing_twig[0], lies_told) |
|
182 | 182 | |
|
183 | 183 | def __getattr__(self, item): |
|
184 | 184 | return SerialLiar(self.max_fibbing_twig, self.lies_told + 1) |
|
185 | 185 | |
|
186 | 186 | #----------------------------------------------------------------------------- |
|
187 | 187 | # Tests |
|
188 | 188 | #----------------------------------------------------------------------------- |
|
189 | 189 | |
|
190 | 190 | def test_info(): |
|
191 | 191 | "Check that Inspector.info fills out various fields as expected." |
|
192 | 192 | i = inspector.info(Call, oname="Call") |
|
193 | 193 | assert i["type_name"] == "type" |
|
194 | 194 | expected_class = str(type(type)) # <class 'type'> (Python 3) or <type 'type'> |
|
195 | 195 | assert i["base_class"] == expected_class |
|
196 | 196 | assert re.search( |
|
197 | 197 | "<class 'IPython.core.tests.test_oinspect.Call'( at 0x[0-9a-f]{1,9})?>", |
|
198 | 198 | i["string_form"], |
|
199 | 199 | ) |
|
200 | 200 | fname = __file__ |
|
201 | 201 | if fname.endswith(".pyc"): |
|
202 | 202 | fname = fname[:-1] |
|
203 | 203 | # case-insensitive comparison needed on some filesystems |
|
204 | 204 | # e.g. Windows: |
|
205 | 205 | assert i["file"].lower() == compress_user(fname).lower() |
|
206 | 206 | assert i["definition"] == None |
|
207 | 207 | assert i["docstring"] == Call.__doc__ |
|
208 | 208 | assert i["source"] == None |
|
209 | 209 | assert i["isclass"] is True |
|
210 | 210 | assert i["init_definition"] == "Call(x, y=1)" |
|
211 | 211 | assert i["init_docstring"] == Call.__init__.__doc__ |
|
212 | 212 | |
|
213 | 213 | i = inspector.info(Call, detail_level=1) |
|
214 | 214 | assert i["source"] is not None |
|
215 | 215 | assert i["docstring"] == None |
|
216 | 216 | |
|
217 | 217 | c = Call(1) |
|
218 | 218 | c.__doc__ = "Modified instance docstring" |
|
219 | 219 | i = inspector.info(c) |
|
220 | 220 | assert i["type_name"] == "Call" |
|
221 | 221 | assert i["docstring"] == "Modified instance docstring" |
|
222 | 222 | assert i["class_docstring"] == Call.__doc__ |
|
223 | 223 | assert i["init_docstring"] == Call.__init__.__doc__ |
|
224 | 224 | assert i["call_docstring"] == Call.__call__.__doc__ |
|
225 | 225 | |
|
226 | 226 | |
|
227 | 227 | def test_class_signature(): |
|
228 | 228 | info = inspector.info(HasSignature, "HasSignature") |
|
229 | 229 | assert info["init_definition"] == "HasSignature(test)" |
|
230 | 230 | assert info["init_docstring"] == HasSignature.__init__.__doc__ |
|
231 | 231 | |
|
232 | 232 | |
|
233 | 233 | def test_info_awkward(): |
|
234 | 234 | # Just test that this doesn't throw an error. |
|
235 | 235 | inspector.info(Awkward()) |
|
236 | 236 | |
|
237 | 237 | def test_bool_raise(): |
|
238 | 238 | inspector.info(NoBoolCall()) |
|
239 | 239 | |
|
240 | 240 | def test_info_serialliar(): |
|
241 | 241 | fib_tracker = [0] |
|
242 | 242 | inspector.info(SerialLiar(fib_tracker)) |
|
243 | 243 | |
|
244 | 244 | # Nested attribute access should be cut off at 100 levels deep to avoid |
|
245 | 245 | # infinite loops: https://github.com/ipython/ipython/issues/9122 |
|
246 | 246 | assert fib_tracker[0] < 9000 |
|
247 | 247 | |
|
248 | 248 | def support_function_one(x, y=2, *a, **kw): |
|
249 | 249 | """A simple function.""" |
|
250 | 250 | |
|
251 | 251 | def test_calldef_none(): |
|
252 | 252 | # We should ignore __call__ for all of these. |
|
253 | 253 | for obj in [support_function_one, SimpleClass().method, any, str.upper]: |
|
254 | 254 | i = inspector.info(obj) |
|
255 | 255 | assert i["call_def"] is None |
|
256 | 256 | |
|
257 | 257 | |
|
258 | 258 | def f_kwarg(pos, *, kwonly): |
|
259 | 259 | pass |
|
260 | 260 | |
|
261 | 261 | def test_definition_kwonlyargs(): |
|
262 | 262 | i = inspector.info(f_kwarg, oname="f_kwarg") # analysis:ignore |
|
263 | 263 | assert i["definition"] == "f_kwarg(pos, *, kwonly)" |
|
264 | 264 | |
|
265 | 265 | |
|
266 | 266 | def test_getdoc(): |
|
267 | 267 | class A(object): |
|
268 | 268 | """standard docstring""" |
|
269 | 269 | pass |
|
270 | 270 | |
|
271 | 271 | class B(object): |
|
272 | 272 | """standard docstring""" |
|
273 | 273 | def getdoc(self): |
|
274 | 274 | return "custom docstring" |
|
275 | 275 | |
|
276 | 276 | class C(object): |
|
277 | 277 | """standard docstring""" |
|
278 | 278 | def getdoc(self): |
|
279 | 279 | return None |
|
280 | 280 | |
|
281 | 281 | a = A() |
|
282 | 282 | b = B() |
|
283 | 283 | c = C() |
|
284 | 284 | |
|
285 | 285 | assert oinspect.getdoc(a) == "standard docstring" |
|
286 | 286 | assert oinspect.getdoc(b) == "custom docstring" |
|
287 | 287 | assert oinspect.getdoc(c) == "standard docstring" |
|
288 | 288 | |
|
289 | 289 | |
|
290 | 290 | def test_empty_property_has_no_source(): |
|
291 | 291 | i = inspector.info(property(), detail_level=1) |
|
292 | 292 | assert i["source"] is None |
|
293 | 293 | |
|
294 | 294 | |
|
295 | 295 | def test_property_sources(): |
|
296 | 296 | # A simple adder whose source and signature stays |
|
297 | 297 | # the same across Python distributions |
|
298 | 298 | def simple_add(a, b): |
|
299 | 299 | "Adds two numbers" |
|
300 | 300 | return a + b |
|
301 | 301 | |
|
302 | 302 | class A(object): |
|
303 | 303 | @property |
|
304 | 304 | def foo(self): |
|
305 | 305 | return 'bar' |
|
306 | 306 | |
|
307 | 307 | foo = foo.setter(lambda self, v: setattr(self, 'bar', v)) |
|
308 | 308 | |
|
309 | 309 | dname = property(oinspect.getdoc) |
|
310 | 310 | adder = property(simple_add) |
|
311 | 311 | |
|
312 | 312 | i = inspector.info(A.foo, detail_level=1) |
|
313 | 313 | assert "def foo(self):" in i["source"] |
|
314 | 314 | assert "lambda self, v:" in i["source"] |
|
315 | 315 | |
|
316 | 316 | i = inspector.info(A.dname, detail_level=1) |
|
317 | 317 | assert "def getdoc(obj)" in i["source"] |
|
318 | 318 | |
|
319 | 319 | i = inspector.info(A.adder, detail_level=1) |
|
320 | 320 | assert "def simple_add(a, b)" in i["source"] |
|
321 | 321 | |
|
322 | 322 | |
|
323 | 323 | def test_property_docstring_is_in_info_for_detail_level_0(): |
|
324 | 324 | class A(object): |
|
325 | 325 | @property |
|
326 | 326 | def foobar(self): |
|
327 | 327 | """This is `foobar` property.""" |
|
328 | 328 | pass |
|
329 | 329 | |
|
330 | 330 | ip.user_ns["a_obj"] = A() |
|
331 | 331 | assert ( |
|
332 | 332 | "This is `foobar` property." |
|
333 | 333 | == ip.object_inspect("a_obj.foobar", detail_level=0)["docstring"] |
|
334 | 334 | ) |
|
335 | 335 | |
|
336 | 336 | ip.user_ns["a_cls"] = A |
|
337 | 337 | assert ( |
|
338 | 338 | "This is `foobar` property." |
|
339 | 339 | == ip.object_inspect("a_cls.foobar", detail_level=0)["docstring"] |
|
340 | 340 | ) |
|
341 | 341 | |
|
342 | 342 | |
|
343 | 343 | def test_pdef(): |
|
344 | 344 | # See gh-1914 |
|
345 | 345 | def foo(): pass |
|
346 | 346 | inspector.pdef(foo, 'foo') |
|
347 | 347 | |
|
348 | 348 | |
|
349 | 349 | @contextmanager |
|
350 | 350 | def cleanup_user_ns(**kwargs): |
|
351 | 351 | """ |
|
352 | 352 | On exit delete all the keys that were not in user_ns before entering. |
|
353 | 353 | |
|
354 | 354 | It does not restore old values ! |
|
355 | 355 | |
|
356 | 356 | Parameters |
|
357 | 357 | ---------- |
|
358 | 358 | |
|
359 | 359 | **kwargs |
|
360 | 360 | used to update ip.user_ns |
|
361 | 361 | |
|
362 | 362 | """ |
|
363 | 363 | try: |
|
364 | 364 | known = set(ip.user_ns.keys()) |
|
365 | 365 | ip.user_ns.update(kwargs) |
|
366 | 366 | yield |
|
367 | 367 | finally: |
|
368 | 368 | added = set(ip.user_ns.keys()) - known |
|
369 | 369 | for k in added: |
|
370 | 370 | del ip.user_ns[k] |
|
371 | 371 | |
|
372 | 372 | |
|
373 | 373 | def test_pinfo_getindex(): |
|
374 | 374 | def dummy(): |
|
375 | 375 | """ |
|
376 | 376 | MARKER |
|
377 | 377 | """ |
|
378 | 378 | |
|
379 | 379 | container = [dummy] |
|
380 | 380 | with cleanup_user_ns(container=container): |
|
381 | 381 | with AssertPrints("MARKER"): |
|
382 | 382 | ip._inspect("pinfo", "container[0]", detail_level=0) |
|
383 | 383 | assert "container" not in ip.user_ns.keys() |
|
384 | 384 | |
|
385 | 385 | |
|
386 | 386 | def test_qmark_getindex(): |
|
387 | 387 | def dummy(): |
|
388 | 388 | """ |
|
389 | 389 | MARKER 2 |
|
390 | 390 | """ |
|
391 | 391 | |
|
392 | 392 | container = [dummy] |
|
393 | 393 | with cleanup_user_ns(container=container): |
|
394 | 394 | with AssertPrints("MARKER 2"): |
|
395 | 395 | ip.run_cell("container[0]?") |
|
396 | 396 | assert "container" not in ip.user_ns.keys() |
|
397 | 397 | |
|
398 | 398 | |
|
399 | 399 | def test_qmark_getindex_negatif(): |
|
400 | 400 | def dummy(): |
|
401 | 401 | """ |
|
402 | 402 | MARKER 3 |
|
403 | 403 | """ |
|
404 | 404 | |
|
405 | 405 | container = [dummy] |
|
406 | 406 | with cleanup_user_ns(container=container): |
|
407 | 407 | with AssertPrints("MARKER 3"): |
|
408 | 408 | ip.run_cell("container[-1]?") |
|
409 | 409 | assert "container" not in ip.user_ns.keys() |
|
410 | 410 | |
|
411 | 411 | |
|
412 | 412 | |
|
413 | 413 | def test_pinfo_nonascii(): |
|
414 | 414 | # See gh-1177 |
|
415 | 415 | from . import nonascii2 |
|
416 | 416 | ip.user_ns['nonascii2'] = nonascii2 |
|
417 | 417 | ip._inspect('pinfo', 'nonascii2', detail_level=1) |
|
418 | 418 | |
|
419 | 419 | def test_pinfo_type(): |
|
420 | 420 | """ |
|
421 | 421 | type can fail in various edge case, for example `type.__subclass__()` |
|
422 | 422 | """ |
|
423 | 423 | ip._inspect('pinfo', 'type') |
|
424 | 424 | |
|
425 | 425 | |
|
426 | 426 | def test_pinfo_docstring_no_source(): |
|
427 | 427 | """Docstring should be included with detail_level=1 if there is no source""" |
|
428 | 428 | with AssertPrints('Docstring:'): |
|
429 | 429 | ip._inspect('pinfo', 'str.format', detail_level=0) |
|
430 | 430 | with AssertPrints('Docstring:'): |
|
431 | 431 | ip._inspect('pinfo', 'str.format', detail_level=1) |
|
432 | 432 | |
|
433 | 433 | |
|
434 | 434 | def test_pinfo_no_docstring_if_source(): |
|
435 | 435 | """Docstring should not be included with detail_level=1 if source is found""" |
|
436 | 436 | def foo(): |
|
437 | 437 | """foo has a docstring""" |
|
438 | 438 | |
|
439 | 439 | ip.user_ns['foo'] = foo |
|
440 | 440 | |
|
441 | 441 | with AssertPrints('Docstring:'): |
|
442 | 442 | ip._inspect('pinfo', 'foo', detail_level=0) |
|
443 | 443 | with AssertPrints('Source:'): |
|
444 | 444 | ip._inspect('pinfo', 'foo', detail_level=1) |
|
445 | 445 | with AssertNotPrints('Docstring:'): |
|
446 | 446 | ip._inspect('pinfo', 'foo', detail_level=1) |
|
447 | 447 | |
|
448 | 448 | |
|
449 | 449 | def test_pinfo_docstring_if_detail_and_no_source(): |
|
450 | 450 | """ Docstring should be displayed if source info not available """ |
|
451 | 451 | obj_def = '''class Foo(object): |
|
452 | 452 | """ This is a docstring for Foo """ |
|
453 | 453 | def bar(self): |
|
454 | 454 | """ This is a docstring for Foo.bar """ |
|
455 | 455 | pass |
|
456 | 456 | ''' |
|
457 | 457 | |
|
458 | 458 | ip.run_cell(obj_def) |
|
459 | 459 | ip.run_cell('foo = Foo()') |
|
460 | 460 | |
|
461 | 461 | with AssertNotPrints("Source:"): |
|
462 | 462 | with AssertPrints('Docstring:'): |
|
463 | 463 | ip._inspect('pinfo', 'foo', detail_level=0) |
|
464 | 464 | with AssertPrints('Docstring:'): |
|
465 | 465 | ip._inspect('pinfo', 'foo', detail_level=1) |
|
466 | 466 | with AssertPrints('Docstring:'): |
|
467 | 467 | ip._inspect('pinfo', 'foo.bar', detail_level=0) |
|
468 | 468 | |
|
469 | 469 | with AssertNotPrints('Docstring:'): |
|
470 | 470 | with AssertPrints('Source:'): |
|
471 | 471 | ip._inspect('pinfo', 'foo.bar', detail_level=1) |
|
472 | 472 | |
|
473 | 473 | |
|
474 | def test_pinfo_docstring_dynamic(): | |
|
475 | obj_def = """class Bar: | |
|
476 | __custom_documentations__ = { | |
|
477 | "prop" : "cdoc for prop", | |
|
478 | "non_exist" : "cdoc for non_exist", | |
|
479 | } | |
|
480 | @property | |
|
481 | def prop(self): | |
|
482 | ''' | |
|
483 | Docstring for prop | |
|
484 | ''' | |
|
485 | return self._prop | |
|
486 | ||
|
487 | @prop.setter | |
|
488 | def prop(self, v): | |
|
489 | self._prop = v | |
|
490 | """ | |
|
491 | ip.run_cell(obj_def) | |
|
492 | ||
|
493 | ip.run_cell("b = Bar()") | |
|
494 | ||
|
495 | with AssertPrints("Docstring: cdoc for prop"): | |
|
496 | ip.run_line_magic("pinfo", "b.prop") | |
|
497 | ||
|
498 | with AssertPrints("Docstring: cdoc for non_exist"): | |
|
499 | ip.run_line_magic("pinfo", "b.non_exist") | |
|
500 | ||
|
501 | with AssertPrints("Docstring: cdoc for prop"): | |
|
502 | ip.run_cell("b.prop?") | |
|
503 | ||
|
504 | with AssertPrints("Docstring: cdoc for non_exist"): | |
|
505 | ip.run_cell("b.non_exist?") | |
|
506 | ||
|
507 | with AssertPrints("Docstring: <no docstring>"): | |
|
508 | ip.run_cell("b.undefined?") | |
|
509 | ||
|
510 | ||
|
474 | 511 | def test_pinfo_magic(): |
|
475 |
with AssertPrints( |
|
|
476 |
ip._inspect( |
|
|
512 | with AssertPrints("Docstring:"): | |
|
513 | ip._inspect("pinfo", "lsmagic", detail_level=0) | |
|
477 | 514 | |
|
478 |
with AssertPrints( |
|
|
479 |
ip._inspect( |
|
|
515 | with AssertPrints("Source:"): | |
|
516 | ip._inspect("pinfo", "lsmagic", detail_level=1) | |
|
480 | 517 | |
|
481 | 518 | |
|
482 | 519 | def test_init_colors(): |
|
483 | 520 | # ensure colors are not present in signature info |
|
484 | 521 | info = inspector.info(HasSignature) |
|
485 | 522 | init_def = info["init_definition"] |
|
486 | 523 | assert "[0m" not in init_def |
|
487 | 524 | |
|
488 | 525 | |
|
489 | 526 | def test_builtin_init(): |
|
490 | 527 | info = inspector.info(list) |
|
491 | 528 | init_def = info['init_definition'] |
|
492 | 529 | assert init_def is not None |
|
493 | 530 | |
|
494 | 531 | |
|
495 | 532 | def test_render_signature_short(): |
|
496 | 533 | def short_fun(a=1): pass |
|
497 | 534 | sig = oinspect._render_signature( |
|
498 | 535 | signature(short_fun), |
|
499 | 536 | short_fun.__name__, |
|
500 | 537 | ) |
|
501 | 538 | assert sig == "short_fun(a=1)" |
|
502 | 539 | |
|
503 | 540 | |
|
504 | 541 | def test_render_signature_long(): |
|
505 | 542 | from typing import Optional |
|
506 | 543 | |
|
507 | 544 | def long_function( |
|
508 | 545 | a_really_long_parameter: int, |
|
509 | 546 | and_another_long_one: bool = False, |
|
510 | 547 | let_us_make_sure_this_is_looong: Optional[str] = None, |
|
511 | 548 | ) -> bool: pass |
|
512 | 549 | |
|
513 | 550 | sig = oinspect._render_signature( |
|
514 | 551 | signature(long_function), |
|
515 | 552 | long_function.__name__, |
|
516 | 553 | ) |
|
517 | 554 | assert sig in [ |
|
518 | 555 | # Python >=3.9 |
|
519 | 556 | '''\ |
|
520 | 557 | long_function( |
|
521 | 558 | a_really_long_parameter: int, |
|
522 | 559 | and_another_long_one: bool = False, |
|
523 | 560 | let_us_make_sure_this_is_looong: Optional[str] = None, |
|
524 | 561 | ) -> bool\ |
|
525 | 562 | ''', |
|
526 | 563 | # Python >=3.7 |
|
527 | 564 | '''\ |
|
528 | 565 | long_function( |
|
529 | 566 | a_really_long_parameter: int, |
|
530 | 567 | and_another_long_one: bool = False, |
|
531 | 568 | let_us_make_sure_this_is_looong: Union[str, NoneType] = None, |
|
532 | 569 | ) -> bool\ |
|
533 | 570 | ''', # Python <=3.6 |
|
534 | 571 | '''\ |
|
535 | 572 | long_function( |
|
536 | 573 | a_really_long_parameter:int, |
|
537 | 574 | and_another_long_one:bool=False, |
|
538 | 575 | let_us_make_sure_this_is_looong:Union[str, NoneType]=None, |
|
539 | 576 | ) -> bool\ |
|
540 | 577 | ''', |
|
541 | 578 | ] |
@@ -1,1499 +1,1574 b'' | |||
|
1 | 1 | ============ |
|
2 | 2 | 8.x Series |
|
3 | 3 | ============ |
|
4 | 4 | |
|
5 | .. _version 8.12.0: | |
|
6 | ||
|
7 | ||
|
8 | Dynamic documentation dispatch | |
|
9 | ------------------------------ | |
|
10 | ||
|
11 | ||
|
12 | We are experimenting with dynamic documentation dispatch for object attribute. | |
|
13 | See :ghissue:`13860`. The goal is to allow object to define documentation for | |
|
14 | their attributes, properties, even when those are dynamically defined with | |
|
15 | `__getattr__`. | |
|
16 | ||
|
17 | In particular when those objects are base types it can be useful to show the | |
|
18 | documentation | |
|
19 | ||
|
20 | ||
|
21 | .. code:: | |
|
22 | ||
|
23 | In [1]: class User: | |
|
24 | ...: | |
|
25 | ...: __custom_documentations__ = { | |
|
26 | ...: "first": "The first name of the user.", | |
|
27 | ...: "last": "The last name of the user.", | |
|
28 | ...: } | |
|
29 | ...: | |
|
30 | ...: first:str | |
|
31 | ...: last:str | |
|
32 | ...: | |
|
33 | ...: def __init__(self, first, last): | |
|
34 | ...: self.first = first | |
|
35 | ...: self.last = last | |
|
36 | ...: | |
|
37 | ...: @property | |
|
38 | ...: def full(self): | |
|
39 | ...: """`self.first` and `self.last` joined by a space.""" | |
|
40 | ...: return self.first + " " + self.last | |
|
41 | ...: | |
|
42 | ...: | |
|
43 | ...: user = Person('Jane', 'Doe') | |
|
44 | ||
|
45 | In [2]: user.first? | |
|
46 | Type: str | |
|
47 | String form: Jane | |
|
48 | Length: 4 | |
|
49 | Docstring: the first name of a the person object, a str | |
|
50 | Class docstring: | |
|
51 | .... | |
|
52 | ||
|
53 | In [3]: user.last? | |
|
54 | Type: str | |
|
55 | String form: Doe | |
|
56 | Length: 3 | |
|
57 | Docstring: the last name, also a str | |
|
58 | ... | |
|
59 | ||
|
60 | ||
|
61 | We can see here the symmetry with IPython looking for the docstring on the | |
|
62 | properties:: | |
|
63 | ||
|
64 | ||
|
65 | In [4]: user.full? | |
|
66 | HERE | |
|
67 | Type: property | |
|
68 | String form: <property object at 0x102bb15d0> | |
|
69 | Docstring: first and last join by a space | |
|
70 | ||
|
71 | ||
|
72 | Note that while in the above example we use a static dictionary, libraries may | |
|
73 | decide to use a custom object that define ``__getitem__``, we caution against | |
|
74 | using objects that would trigger computation to show documentation, but it is | |
|
75 | sometime preferable for highly dynamic code that for example export ans API as | |
|
76 | object. | |
|
77 | ||
|
78 | ||
|
79 | ||
|
5 | 80 | .. _version 8.11.0: |
|
6 | 81 | |
|
7 | 82 | IPython 8.11 |
|
8 | 83 | ------------ |
|
9 | 84 | |
|
10 | 85 | Back on almost regular monthly schedule for IPython with end-of-month |
|
11 | 86 | really-late-Friday release to make sure some bugs are properly fixed. |
|
12 | 87 | Small addition of with a few new features, bugfix and UX improvements. |
|
13 | 88 | |
|
14 | 89 | This is a non-exhaustive list, but among other you will find: |
|
15 | 90 | |
|
16 | 91 | Faster Traceback Highlighting |
|
17 | 92 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|
18 | 93 | |
|
19 | 94 | Resurrection of pre-IPython-8 traceback highlighting code. |
|
20 | 95 | |
|
21 | 96 | Really long and complicated files were slow to highlight in traceback with |
|
22 | 97 | IPython 8 despite upstream improvement that make many case better. Therefore |
|
23 | 98 | starting with IPython 8.11 when one of the highlighted file is more than 10 000 |
|
24 | 99 | line long by default, we'll fallback to a faster path that does not have all the |
|
25 | 100 | features of highlighting failing AST nodes. |
|
26 | 101 | |
|
27 | 102 | This can be configures by setting the value of |
|
28 | 103 | ``IPython.code.ultratb.FAST_THRESHOLD`` to an arbitrary low or large value. |
|
29 | 104 | |
|
30 | 105 | |
|
31 | 106 | Autoreload verbosity |
|
32 | 107 | ~~~~~~~~~~~~~~~~~~~~ |
|
33 | 108 | |
|
34 | 109 | We introduce more descriptive names for the ``%autoreload`` parameter: |
|
35 | 110 | |
|
36 | 111 | - ``%autoreload now`` (also ``%autoreload``) - perform autoreload immediately. |
|
37 | 112 | - ``%autoreload off`` (also ``%autoreload 0``) - turn off autoreload. |
|
38 | 113 | - ``%autoreload explicit`` (also ``%autoreload 1``) - turn on autoreload only for modules |
|
39 | 114 | whitelisted by ``%aimport`` statements. |
|
40 | 115 | - ``%autoreload all`` (also ``%autoreload 2``) - turn on autoreload for all modules except those |
|
41 | 116 | blacklisted by ``%aimport`` statements. |
|
42 | 117 | - ``%autoreload complete`` (also ``%autoreload 3``) - all the fatures of ``all`` but also adding new |
|
43 | 118 | objects from the imported modules (see |
|
44 | 119 | IPython/extensions/tests/test_autoreload.py::test_autoload_newly_added_objects). |
|
45 | 120 | |
|
46 | 121 | The original designations (e.g. "2") still work, and these new ones are case-insensitive. |
|
47 | 122 | |
|
48 | 123 | Additionally, the option ``--print`` or ``-p`` can be added to the line to print the names of |
|
49 | 124 | modules being reloaded. Similarly, ``--log`` or ``-l`` will output the names to the logger at INFO |
|
50 | 125 | level. Both can be used simultaneously. |
|
51 | 126 | |
|
52 | 127 | The parsing logic for ``%aimport`` is now improved such that modules can be whitelisted and |
|
53 | 128 | blacklisted in the same line, e.g. it's now possible to call ``%aimport os, -math`` to include |
|
54 | 129 | ``os`` for ``%autoreload explicit`` and exclude ``math`` for modes ``all`` and ``complete``. |
|
55 | 130 | |
|
56 | 131 | Terminal shortcuts customization |
|
57 | 132 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|
58 | 133 | |
|
59 | 134 | Previously modifying shortcuts was only possible by hooking into startup files |
|
60 | 135 | and practically limited to adding new shortcuts or removing all shortcuts bound |
|
61 | 136 | to a specific key. This release enables users to override existing terminal |
|
62 | 137 | shortcuts, disable them or add new keybindings. |
|
63 | 138 | |
|
64 | 139 | For example, to set the :kbd:`right` to accept a single character of auto-suggestion |
|
65 | 140 | you could use:: |
|
66 | 141 | |
|
67 | 142 | my_shortcuts = [ |
|
68 | 143 | { |
|
69 | 144 | "command": "IPython:auto_suggest.accept_character", |
|
70 | 145 | "new_keys": ["right"] |
|
71 | 146 | } |
|
72 | 147 | ] |
|
73 | 148 | %config TerminalInteractiveShell.shortcuts = my_shortcuts |
|
74 | 149 | |
|
75 | 150 | You can learn more in :std:configtrait:`TerminalInteractiveShell.shortcuts` |
|
76 | 151 | configuration reference. |
|
77 | 152 | |
|
78 | 153 | Miscellaneous |
|
79 | 154 | ~~~~~~~~~~~~~ |
|
80 | 155 | |
|
81 | 156 | - ``%gui`` should now support PySide6. :ghpull:`13864` |
|
82 | 157 | - Cli shortcuts can now be configured :ghpull:`13928`, see above. |
|
83 | 158 | (note that there might be an issue with prompt_toolkit 3.0.37 and shortcut configuration). |
|
84 | 159 | |
|
85 | 160 | - Capture output should now respect ``;`` semicolon to suppress output. |
|
86 | 161 | :ghpull:`13940` |
|
87 | 162 | - Base64 encoded images (in jupyter frontend), will not have trailing newlines. |
|
88 | 163 | :ghpull:`13941` |
|
89 | 164 | |
|
90 | 165 | As usual you can find the full list of PRs on GitHub under `the 8.11 milestone |
|
91 | 166 | <https://github.com/ipython/ipython/milestone/113?closed=1>`__. |
|
92 | 167 | |
|
93 | 168 | Thanks to the `D. E. Shaw group <https://deshaw.com/>`__ for sponsoring |
|
94 | 169 | work on IPython and related libraries. |
|
95 | 170 | |
|
96 | 171 | .. _version 8.10.0: |
|
97 | ||
|
172 | ||
|
98 | 173 | IPython 8.10 |
|
99 | 174 | ------------ |
|
100 | 175 | |
|
101 | 176 | Out of schedule release of IPython with minor fixes to patch a potential CVE-2023-24816. |
|
102 | 177 | This is a really low severity CVE that you most likely are not affected by unless: |
|
103 | 178 | |
|
104 | 179 | - You are on windows. |
|
105 | 180 | - You have a custom build of Python without ``_ctypes`` |
|
106 | 181 | - You cd or start IPython or Jupyter in untrusted directory which names may be |
|
107 | 182 | valid shell commands. |
|
108 | 183 | |
|
109 | 184 | You can read more on `the advisory |
|
110 |
<https://github.com/ipython/ipython/security/advisories/GHSA-29gw-9793-fvw7>`__. |
|
|
185 | <https://github.com/ipython/ipython/security/advisories/GHSA-29gw-9793-fvw7>`__. | |
|
111 | 186 | |
|
112 | 187 | In addition to fixing this CVE we also fix a couple of outstanding bugs and issues. |
|
113 | 188 | |
|
114 | 189 | As usual you can find the full list of PRs on GitHub under `the 8.10 milestone |
|
115 | 190 | <https://github.com/ipython/ipython/milestone/112?closed=1>`__. |
|
116 | 191 | |
|
117 | 192 | In Particular: |
|
118 | 193 | |
|
119 | 194 | - bump minimum numpy to `>=1.21` version following NEP29. :ghpull:`13930` |
|
120 | 195 | - fix for compatibility with MyPy 1.0. :ghpull:`13933` |
|
121 | 196 | - fix nbgrader stalling when IPython's ``showtraceback`` function is |
|
122 | 197 | monkeypatched. :ghpull:`13934` |
|
123 | 198 | |
|
124 | 199 | |
|
125 | 200 | |
|
126 | 201 | As this release also contains those minimal changes in addition to fixing the |
|
127 | 202 | CVE I decided to bump the minor version anyway. |
|
128 | 203 | |
|
129 | 204 | This will not affect the normal release schedule, so IPython 8.11 is due in |
|
130 | 205 | about 2 weeks. |
|
131 | 206 | |
|
132 | 207 | .. _version 8.9.0: |
|
133 | 208 | |
|
134 | 209 | IPython 8.9.0 |
|
135 | 210 | ------------- |
|
136 | 211 | |
|
137 | 212 | Second release of IPython in 2023, last Friday of the month, we are back on |
|
138 | 213 | track. This is a small release with a few bug-fixes, and improvements, mostly |
|
139 | 214 | with respect to terminal shortcuts. |
|
140 | 215 | |
|
141 | 216 | |
|
142 | 217 | The biggest improvement for 8.9 is a drastic amelioration of the |
|
143 | 218 | auto-suggestions sponsored by D.E. Shaw and implemented by the more and more |
|
144 | 219 | active contributor `@krassowski <https://github.com/krassowski>`. |
|
145 | 220 | |
|
146 | 221 | - ``right`` accepts a single character from suggestion |
|
147 | 222 | - ``ctrl+right`` accepts a semantic token (macos default shortcuts take |
|
148 | 223 | precedence and need to be disabled to make this work) |
|
149 | 224 | - ``backspace`` deletes a character and resumes hinting autosuggestions |
|
150 | 225 | - ``ctrl-left`` accepts suggestion and moves cursor left one character. |
|
151 | 226 | - ``backspace`` deletes a character and resumes hinting autosuggestions |
|
152 | 227 | - ``down`` moves to suggestion to later in history when no lines are present below the cursors. |
|
153 | 228 | - ``up`` moves to suggestion from earlier in history when no lines are present above the cursor. |
|
154 | 229 | |
|
155 | 230 | This is best described by the Gif posted by `@krassowski |
|
156 | 231 | <https://github.com/krassowski>`, and in the PR itself :ghpull:`13888`. |
|
157 | 232 | |
|
158 | 233 | .. image:: ../_images/autosuggest.gif |
|
159 | 234 | |
|
160 | 235 | Please report any feedback in order for us to improve the user experience. |
|
161 | 236 | In particular we are also working on making the shortcuts configurable. |
|
162 | 237 | |
|
163 | 238 | If you are interested in better terminal shortcuts, I also invite you to |
|
164 | 239 | participate in issue `13879 |
|
165 | 240 | <https://github.com/ipython/ipython/issues/13879>`__. |
|
166 | 241 | |
|
167 | 242 | |
|
168 | 243 | As we follow `NEP29 |
|
169 | 244 | <https://numpy.org/neps/nep-0029-deprecation_policy.html>`__, next version of |
|
170 | 245 | IPython will officially stop supporting numpy 1.20, and will stop supporting |
|
171 | 246 | Python 3.8 after April release. |
|
172 | 247 | |
|
173 | 248 | As usual you can find the full list of PRs on GitHub under `the 8.9 milestone |
|
174 | 249 | <https://github.com/ipython/ipython/milestone/111?closed=1>`__. |
|
175 | 250 | |
|
176 | 251 | |
|
177 | 252 | Thanks to the `D. E. Shaw group <https://deshaw.com/>`__ for sponsoring |
|
178 | 253 | work on IPython and related libraries. |
|
179 | 254 | |
|
180 | 255 | .. _version 8.8.0: |
|
181 | 256 | |
|
182 | 257 | IPython 8.8.0 |
|
183 | 258 | ------------- |
|
184 | 259 | |
|
185 | 260 | First release of IPython in 2023 as there was no release at the end of |
|
186 | 261 | December. |
|
187 | 262 | |
|
188 | 263 | This is an unusually big release (relatively speaking) with more than 15 Pull |
|
189 | 264 | Requests merged. |
|
190 | 265 | |
|
191 | 266 | Of particular interest are: |
|
192 | 267 | |
|
193 | 268 | - :ghpull:`13852` that replaces the greedy completer and improves |
|
194 | 269 | completion, in particular for dictionary keys. |
|
195 | 270 | - :ghpull:`13858` that adds ``py.typed`` to ``setup.cfg`` to make sure it is |
|
196 | 271 | bundled in wheels. |
|
197 | 272 | - :ghpull:`13869` that implements tab completions for IPython options in the |
|
198 | 273 | shell when using `argcomplete <https://github.com/kislyuk/argcomplete>`. I |
|
199 | 274 | believe this also needs a recent version of Traitlets. |
|
200 | 275 | - :ghpull:`13865` makes the ``inspector`` class of `InteractiveShell` |
|
201 | 276 | configurable. |
|
202 | 277 | - :ghpull:`13880` that removes minor-version entrypoints as the minor version |
|
203 | 278 | entry points that would be included in the wheel would be the one of the |
|
204 | 279 | Python version that was used to build the ``whl`` file. |
|
205 | 280 | |
|
206 | 281 | In no particular order, the rest of the changes update the test suite to be |
|
207 | 282 | compatible with Pygments 2.14, various docfixes, testing on more recent python |
|
208 | 283 | versions and various updates. |
|
209 | 284 | |
|
210 | 285 | As usual you can find the full list of PRs on GitHub under `the 8.8 milestone |
|
211 | 286 | <https://github.com/ipython/ipython/milestone/110>`__. |
|
212 | 287 | |
|
213 | 288 | Many thanks to @krassowski for the many PRs and @jasongrout for reviewing and |
|
214 | 289 | merging contributions. |
|
215 | 290 | |
|
216 | 291 | Thanks to the `D. E. Shaw group <https://deshaw.com/>`__ for sponsoring |
|
217 | 292 | work on IPython and related libraries. |
|
218 | 293 | |
|
219 | 294 | .. _version 8.7.0: |
|
220 | 295 | |
|
221 | 296 | IPython 8.7.0 |
|
222 | 297 | ------------- |
|
223 | 298 | |
|
224 | 299 | |
|
225 | 300 | Small release of IPython with a couple of bug fixes and new features for this |
|
226 | 301 | month. Next month is the end of year, it is unclear if there will be a release |
|
227 | 302 | close to the new year's eve, or if the next release will be at the end of January. |
|
228 | 303 | |
|
229 | 304 | Here are a few of the relevant fixes, |
|
230 | 305 | as usual you can find the full list of PRs on GitHub under `the 8.7 milestone |
|
231 | 306 | <https://github.com/ipython/ipython/pulls?q=milestone%3A8.7>`__. |
|
232 | 307 | |
|
233 | 308 | |
|
234 | 309 | - :ghpull:`13834` bump the minimum prompt toolkit to 3.0.11. |
|
235 | 310 | - IPython shipped with the ``py.typed`` marker now, and we are progressively |
|
236 | 311 | adding more types. :ghpull:`13831` |
|
237 | 312 | - :ghpull:`13817` add configuration of code blacks formatting. |
|
238 | 313 | |
|
239 | 314 | |
|
240 | 315 | Thanks to the `D. E. Shaw group <https://deshaw.com/>`__ for sponsoring |
|
241 | 316 | work on IPython and related libraries. |
|
242 | 317 | |
|
243 | 318 | |
|
244 | 319 | .. _version 8.6.0: |
|
245 | 320 | |
|
246 | 321 | IPython 8.6.0 |
|
247 | 322 | ------------- |
|
248 | 323 | |
|
249 | 324 | Back to a more regular release schedule (at least I try), as Friday is |
|
250 | 325 | already over by more than 24h hours. This is a slightly bigger release with a |
|
251 | 326 | few new features that contain no less than 25 PRs. |
|
252 | 327 | |
|
253 | 328 | We'll notably found a couple of non negligible changes: |
|
254 | 329 | |
|
255 | 330 | The ``install_ext`` and related functions have been removed after being |
|
256 | 331 | deprecated for years. You can use pip to install extensions. ``pip`` did not |
|
257 | 332 | exist when ``install_ext`` was introduced. You can still load local extensions |
|
258 | 333 | without installing them. Just set your ``sys.path`` for example. :ghpull:`13744` |
|
259 | 334 | |
|
260 | 335 | IPython now has extra entry points that use the major *and minor* version of |
|
261 | 336 | python. For some of you this means that you can do a quick ``ipython3.10`` to |
|
262 | 337 | launch IPython from the Python 3.10 interpreter, while still using Python 3.11 |
|
263 | 338 | as your main Python. :ghpull:`13743` |
|
264 | 339 | |
|
265 | 340 | The completer matcher API has been improved. See :ghpull:`13745`. This should |
|
266 | 341 | improve the type inference and improve dict keys completions in many use case. |
|
267 | 342 | Thanks ``@krassowski`` for all the work, and the D.E. Shaw group for sponsoring |
|
268 | 343 | it. |
|
269 | 344 | |
|
270 | 345 | The color of error nodes in tracebacks can now be customized. See |
|
271 | 346 | :ghpull:`13756`. This is a private attribute until someone finds the time to |
|
272 | 347 | properly add a configuration option. Note that with Python 3.11 that also shows |
|
273 | 348 | the relevant nodes in traceback, it would be good to leverage this information |
|
274 | 349 | (plus the "did you mean" info added on attribute errors). But that's likely work |
|
275 | 350 | I won't have time to do before long, so contributions welcome. |
|
276 | 351 | |
|
277 | 352 | As we follow NEP 29, we removed support for numpy 1.19 :ghpull:`13760`. |
|
278 | 353 | |
|
279 | 354 | |
|
280 | 355 | The ``open()`` function present in the user namespace by default will now refuse |
|
281 | 356 | to open the file descriptors 0,1,2 (stdin, out, err), to avoid crashing IPython. |
|
282 | 357 | This mostly occurs in teaching context when incorrect values get passed around. |
|
283 | 358 | |
|
284 | 359 | |
|
285 | 360 | The ``?``, ``??``, and corresponding ``pinfo``, ``pinfo2`` magics can now find |
|
286 | 361 | objects inside arrays. That is to say, the following now works:: |
|
287 | 362 | |
|
288 | 363 | |
|
289 | 364 | >>> def my_func(*arg, **kwargs):pass |
|
290 | 365 | >>> container = [my_func] |
|
291 | 366 | >>> container[0]? |
|
292 | 367 | |
|
293 | 368 | |
|
294 | 369 | If ``container`` define a custom ``getitem``, this __will__ trigger the custom |
|
295 | 370 | method. So don't put side effects in your ``getitems``. Thanks to the D.E. Shaw |
|
296 | 371 | group for the request and sponsoring the work. |
|
297 | 372 | |
|
298 | 373 | |
|
299 | 374 | As usual you can find the full list of PRs on GitHub under `the 8.6 milestone |
|
300 | 375 | <https://github.com/ipython/ipython/pulls?q=milestone%3A8.6>`__. |
|
301 | 376 | |
|
302 | 377 | Thanks to all hacktoberfest contributors, please contribute to |
|
303 | 378 | `closember.org <https://closember.org/>`__. |
|
304 | 379 | |
|
305 | 380 | Thanks to the `D. E. Shaw group <https://deshaw.com/>`__ for sponsoring |
|
306 | 381 | work on IPython and related libraries. |
|
307 | 382 | |
|
308 | 383 | .. _version 8.5.0: |
|
309 | 384 | |
|
310 | 385 | IPython 8.5.0 |
|
311 | 386 | ------------- |
|
312 | 387 | |
|
313 | 388 | First release since a couple of month due to various reasons and timing preventing |
|
314 | 389 | me for sticking to the usual monthly release the last Friday of each month. This |
|
315 | 390 | is of non negligible size as it has more than two dozen PRs with various fixes |
|
316 | 391 | an bug fixes. |
|
317 | 392 | |
|
318 | 393 | Many thanks to everybody who contributed PRs for your patience in review and |
|
319 | 394 | merges. |
|
320 | 395 | |
|
321 | 396 | Here is a non-exhaustive list of changes that have been implemented for IPython |
|
322 | 397 | 8.5.0. As usual you can find the full list of issues and PRs tagged with `the |
|
323 | 398 | 8.5 milestone |
|
324 | 399 | <https://github.com/ipython/ipython/pulls?q=is%3Aclosed+milestone%3A8.5+>`__. |
|
325 | 400 | |
|
326 | 401 | - Added a shortcut for accepting auto suggestion. The End key shortcut for |
|
327 | 402 | accepting auto-suggestion This binding works in Vi mode too, provided |
|
328 | 403 | ``TerminalInteractiveShell.emacs_bindings_in_vi_insert_mode`` is set to be |
|
329 | 404 | ``True`` :ghpull:`13566`. |
|
330 | 405 | |
|
331 | 406 | - No popup in window for latex generation when generating latex (e.g. via |
|
332 | 407 | `_latex_repr_`) no popup window is shows under Windows. :ghpull:`13679` |
|
333 | 408 | |
|
334 | 409 | - Fixed error raised when attempting to tab-complete an input string with |
|
335 | 410 | consecutive periods or forward slashes (such as "file:///var/log/..."). |
|
336 | 411 | :ghpull:`13675` |
|
337 | 412 | |
|
338 | 413 | - Relative filenames in Latex rendering : |
|
339 | 414 | The `latex_to_png_dvipng` command internally generates input and output file |
|
340 | 415 | arguments to `latex` and `dvipis`. These arguments are now generated as |
|
341 | 416 | relative files to the current working directory instead of absolute file |
|
342 | 417 | paths. This solves a problem where the current working directory contains |
|
343 | 418 | characters that are not handled properly by `latex` and `dvips`. There are |
|
344 | 419 | no changes to the user API. :ghpull:`13680` |
|
345 | 420 | |
|
346 | 421 | - Stripping decorators bug: Fixed bug which meant that ipython code blocks in |
|
347 | 422 | restructured text documents executed with the ipython-sphinx extension |
|
348 | 423 | skipped any lines of code containing python decorators. :ghpull:`13612` |
|
349 | 424 | |
|
350 | 425 | - Allow some modules with frozen dataclasses to be reloaded. :ghpull:`13732` |
|
351 | 426 | - Fix paste magic on wayland. :ghpull:`13671` |
|
352 | 427 | - show maxlen in deque's repr. :ghpull:`13648` |
|
353 | 428 | |
|
354 | 429 | Restore line numbers for Input |
|
355 | 430 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|
356 | 431 | |
|
357 | 432 | Line number information in tracebacks from input are restored. |
|
358 | 433 | Line numbers from input were removed during the transition to v8 enhanced traceback reporting. |
|
359 | 434 | |
|
360 | 435 | So, instead of:: |
|
361 | 436 | |
|
362 | 437 | --------------------------------------------------------------------------- |
|
363 | 438 | ZeroDivisionError Traceback (most recent call last) |
|
364 | 439 | Input In [3], in <cell line: 1>() |
|
365 | 440 | ----> 1 myfunc(2) |
|
366 | 441 | |
|
367 | 442 | Input In [2], in myfunc(z) |
|
368 | 443 | 1 def myfunc(z): |
|
369 | 444 | ----> 2 foo.boo(z-1) |
|
370 | 445 | |
|
371 | 446 | File ~/code/python/ipython/foo.py:3, in boo(x) |
|
372 | 447 | 2 def boo(x): |
|
373 | 448 | ----> 3 return 1/(1-x) |
|
374 | 449 | |
|
375 | 450 | ZeroDivisionError: division by zero |
|
376 | 451 | |
|
377 | 452 | The error traceback now looks like:: |
|
378 | 453 | |
|
379 | 454 | --------------------------------------------------------------------------- |
|
380 | 455 | ZeroDivisionError Traceback (most recent call last) |
|
381 | 456 | Cell In [3], line 1 |
|
382 | 457 | ----> 1 myfunc(2) |
|
383 | 458 | |
|
384 | 459 | Cell In [2], line 2, in myfunc(z) |
|
385 | 460 | 1 def myfunc(z): |
|
386 | 461 | ----> 2 foo.boo(z-1) |
|
387 | 462 | |
|
388 | 463 | File ~/code/python/ipython/foo.py:3, in boo(x) |
|
389 | 464 | 2 def boo(x): |
|
390 | 465 | ----> 3 return 1/(1-x) |
|
391 | 466 | |
|
392 | 467 | ZeroDivisionError: division by zero |
|
393 | 468 | |
|
394 | 469 | or, with xmode=Plain:: |
|
395 | 470 | |
|
396 | 471 | Traceback (most recent call last): |
|
397 | 472 | Cell In [12], line 1 |
|
398 | 473 | myfunc(2) |
|
399 | 474 | Cell In [6], line 2 in myfunc |
|
400 | 475 | foo.boo(z-1) |
|
401 | 476 | File ~/code/python/ipython/foo.py:3 in boo |
|
402 | 477 | return 1/(1-x) |
|
403 | 478 | ZeroDivisionError: division by zero |
|
404 | 479 | |
|
405 | 480 | :ghpull:`13560` |
|
406 | 481 | |
|
407 | 482 | New setting to silence warning if working inside a virtual environment |
|
408 | 483 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|
409 | 484 | |
|
410 | 485 | Previously, when starting IPython in a virtual environment without IPython installed (so IPython from the global environment is used), the following warning was printed: |
|
411 | 486 | |
|
412 | 487 | Attempting to work in a virtualenv. If you encounter problems, please install IPython inside the virtualenv. |
|
413 | 488 | |
|
414 | 489 | This warning can be permanently silenced by setting ``c.InteractiveShell.warn_venv`` to ``False`` (the default is ``True``). |
|
415 | 490 | |
|
416 | 491 | :ghpull:`13706` |
|
417 | 492 | |
|
418 | 493 | ------- |
|
419 | 494 | |
|
420 | 495 | Thanks to the `D. E. Shaw group <https://deshaw.com/>`__ for sponsoring |
|
421 | 496 | work on IPython and related libraries. |
|
422 | 497 | |
|
423 | 498 | |
|
424 | 499 | .. _version 8.4.0: |
|
425 | 500 | |
|
426 | 501 | IPython 8.4.0 |
|
427 | 502 | ------------- |
|
428 | 503 | |
|
429 | 504 | As for 7.34, this version contains a single fix: fix uncaught BdbQuit exceptions on ipdb |
|
430 | 505 | exit :ghpull:`13668`, and a single typo fix in documentation: :ghpull:`13682` |
|
431 | 506 | |
|
432 | 507 | Thanks to the `D. E. Shaw group <https://deshaw.com/>`__ for sponsoring |
|
433 | 508 | work on IPython and related libraries. |
|
434 | 509 | |
|
435 | 510 | |
|
436 | 511 | .. _version 8.3.0: |
|
437 | 512 | |
|
438 | 513 | IPython 8.3.0 |
|
439 | 514 | ------------- |
|
440 | 515 | |
|
441 | 516 | - :ghpull:`13625`, using ``?``, ``??``, ``*?`` will not call |
|
442 | 517 | ``set_next_input`` as most frontend allow proper multiline editing and it was |
|
443 | 518 | causing issues for many users of multi-cell frontends. This has been backported to 7.33 |
|
444 | 519 | |
|
445 | 520 | |
|
446 | 521 | - :ghpull:`13600`, ``pre_run_*``-hooks will now have a ``cell_id`` attribute on |
|
447 | 522 | the info object when frontend provides it. This has been backported to 7.33 |
|
448 | 523 | |
|
449 | 524 | - :ghpull:`13624`, fixed :kbd:`End` key being broken after accepting an |
|
450 | 525 | auto-suggestion. |
|
451 | 526 | |
|
452 | 527 | - :ghpull:`13657` fixed an issue where history from different sessions would be mixed. |
|
453 | 528 | |
|
454 | 529 | .. _version 8.2.0: |
|
455 | 530 | |
|
456 | 531 | IPython 8.2.0 |
|
457 | 532 | ------------- |
|
458 | 533 | |
|
459 | 534 | IPython 8.2 mostly bring bugfixes to IPython. |
|
460 | 535 | |
|
461 | 536 | - Auto-suggestion can now be elected with the ``end`` key. :ghpull:`13566` |
|
462 | 537 | - Some traceback issues with ``assert etb is not None`` have been fixed. :ghpull:`13588` |
|
463 | 538 | - History is now pulled from the sqitel database and not from in-memory. |
|
464 | 539 | In particular when using the ``%paste`` magic, the content of the pasted text will |
|
465 | 540 | be part of the history and not the verbatim text ``%paste`` anymore. :ghpull:`13592` |
|
466 | 541 | - Fix ``Ctrl-\\`` exit cleanup :ghpull:`13603` |
|
467 | 542 | - Fixes to ``ultratb`` ipdb support when used outside of IPython. :ghpull:`13498` |
|
468 | 543 | |
|
469 | 544 | |
|
470 | 545 | I am still trying to fix and investigate :ghissue:`13598`, which seems to be |
|
471 | 546 | random, and would appreciate help if you find a reproducible minimal case. I've |
|
472 | 547 | tried to make various changes to the codebase to mitigate it, but a proper fix |
|
473 | 548 | will be difficult without understanding the cause. |
|
474 | 549 | |
|
475 | 550 | |
|
476 | 551 | All the issues on pull-requests for this release can be found in the `8.2 |
|
477 | 552 | milestone. <https://github.com/ipython/ipython/milestone/100>`__ . And some |
|
478 | 553 | documentation only PR can be found as part of the `7.33 milestone |
|
479 | 554 | <https://github.com/ipython/ipython/milestone/101>`__ (currently not released). |
|
480 | 555 | |
|
481 | 556 | Thanks to the `D. E. Shaw group <https://deshaw.com/>`__ for sponsoring |
|
482 | 557 | work on IPython and related libraries. |
|
483 | 558 | |
|
484 | 559 | .. _version 8.1.1: |
|
485 | 560 | |
|
486 | 561 | IPython 8.1.1 |
|
487 | 562 | ------------- |
|
488 | 563 | |
|
489 | 564 | Fix an issue with virtualenv and Python 3.8 introduced in 8.1 |
|
490 | 565 | |
|
491 | 566 | Revert :ghpull:`13537` (fix an issue with symlinks in virtualenv) that raises an |
|
492 | 567 | error in Python 3.8, and fixed in a different way in :ghpull:`13559`. |
|
493 | 568 | |
|
494 | 569 | .. _version 8.1: |
|
495 | 570 | |
|
496 | 571 | IPython 8.1.0 |
|
497 | 572 | ------------- |
|
498 | 573 | |
|
499 | 574 | IPython 8.1 is the first minor release after 8.0 and fixes a number of bugs and |
|
500 | 575 | updates a few behaviors that were problematic with the 8.0 as with many new major |
|
501 | 576 | release. |
|
502 | 577 | |
|
503 | 578 | Note that beyond the changes listed here, IPython 8.1.0 also contains all the |
|
504 | 579 | features listed in :ref:`version 7.32`. |
|
505 | 580 | |
|
506 | 581 | - Misc and multiple fixes around quotation auto-closing. It is now disabled by |
|
507 | 582 | default. Run with ``TerminalInteractiveShell.auto_match=True`` to re-enabled |
|
508 | 583 | - Require pygments>=2.4.0 :ghpull:`13459`, this was implicit in the code, but |
|
509 | 584 | is now explicit in ``setup.cfg``/``setup.py`` |
|
510 | 585 | - Docs improvement of ``core.magic_arguments`` examples. :ghpull:`13433` |
|
511 | 586 | - Multi-line edit executes too early with await. :ghpull:`13424` |
|
512 | 587 | |
|
513 | 588 | - ``black`` is back as an optional dependency, and autoformatting disabled by |
|
514 | 589 | default until some fixes are implemented (black improperly reformat magics). |
|
515 | 590 | :ghpull:`13471` Additionally the ability to use ``yapf`` as a code |
|
516 | 591 | reformatter has been added :ghpull:`13528` . You can use |
|
517 | 592 | ``TerminalInteractiveShell.autoformatter="black"``, |
|
518 | 593 | ``TerminalInteractiveShell.autoformatter="yapf"`` to re-enable auto formating |
|
519 | 594 | with black, or switch to yapf. |
|
520 | 595 | |
|
521 | 596 | - Fix and issue where ``display`` was not defined. |
|
522 | 597 | |
|
523 | 598 | - Auto suggestions are now configurable. Currently only |
|
524 | 599 | ``AutoSuggestFromHistory`` (default) and ``None``. new provider contribution |
|
525 | 600 | welcomed. :ghpull:`13475` |
|
526 | 601 | |
|
527 | 602 | - multiple packaging/testing improvement to simplify downstream packaging |
|
528 | 603 | (xfail with reasons, try to not access network...). |
|
529 | 604 | |
|
530 | 605 | - Update deprecation. ``InteractiveShell.magic`` internal method has been |
|
531 | 606 | deprecated for many years but did not emit a warning until now. |
|
532 | 607 | |
|
533 | 608 | - internal ``appended_to_syspath`` context manager has been deprecated. |
|
534 | 609 | |
|
535 | 610 | - fix an issue with symlinks in virtualenv :ghpull:`13537` (Reverted in 8.1.1) |
|
536 | 611 | |
|
537 | 612 | - Fix an issue with vim mode, where cursor would not be reset on exit :ghpull:`13472` |
|
538 | 613 | |
|
539 | 614 | - ipython directive now remove only known pseudo-decorators :ghpull:`13532` |
|
540 | 615 | |
|
541 | 616 | - ``IPython/lib/security`` which used to be used for jupyter notebook has been |
|
542 | 617 | removed. |
|
543 | 618 | |
|
544 | 619 | - Fix an issue where ``async with`` would execute on new lines. :ghpull:`13436` |
|
545 | 620 | |
|
546 | 621 | |
|
547 | 622 | We want to remind users that IPython is part of the Jupyter organisations, and |
|
548 | 623 | thus governed by a Code of Conduct. Some of the behavior we have seen on GitHub is not acceptable. |
|
549 | 624 | Abuse and non-respectful comments on discussion will not be tolerated. |
|
550 | 625 | |
|
551 | 626 | Many thanks to all the contributors to this release, many of the above fixed issues and |
|
552 | 627 | new features were done by first time contributors, showing there is still |
|
553 | 628 | plenty of easy contribution possible in IPython |
|
554 | 629 | . You can find all individual contributions |
|
555 | 630 | to this milestone `on github <https://github.com/ipython/ipython/milestone/91>`__. |
|
556 | 631 | |
|
557 | 632 | Thanks as well to the `D. E. Shaw group <https://deshaw.com/>`__ for sponsoring |
|
558 | 633 | work on IPython and related libraries. In particular the Lazy autoloading of |
|
559 | 634 | magics that you will find described in the 7.32 release notes. |
|
560 | 635 | |
|
561 | 636 | |
|
562 | 637 | .. _version 8.0.1: |
|
563 | 638 | |
|
564 | 639 | IPython 8.0.1 (CVE-2022-21699) |
|
565 | 640 | ------------------------------ |
|
566 | 641 | |
|
567 | 642 | IPython 8.0.1, 7.31.1 and 5.11 are security releases that change some default |
|
568 | 643 | values in order to prevent potential Execution with Unnecessary Privileges. |
|
569 | 644 | |
|
570 | 645 | Almost all version of IPython looks for configuration and profiles in current |
|
571 | 646 | working directory. Since IPython was developed before pip and environments |
|
572 | 647 | existed it was used a convenient way to load code/packages in a project |
|
573 | 648 | dependant way. |
|
574 | 649 | |
|
575 | 650 | In 2022, it is not necessary anymore, and can lead to confusing behavior where |
|
576 | 651 | for example cloning a repository and starting IPython or loading a notebook from |
|
577 | 652 | any Jupyter-Compatible interface that has ipython set as a kernel can lead to |
|
578 | 653 | code execution. |
|
579 | 654 | |
|
580 | 655 | |
|
581 | 656 | I did not find any standard way for packaged to advertise CVEs they fix, I'm |
|
582 | 657 | thus trying to add a ``__patched_cves__`` attribute to the IPython module that |
|
583 | 658 | list the CVEs that should have been fixed. This attribute is informational only |
|
584 | 659 | as if a executable has a flaw, this value can always be changed by an attacker. |
|
585 | 660 | |
|
586 | 661 | .. code:: |
|
587 | 662 | |
|
588 | 663 | In [1]: import IPython |
|
589 | 664 | |
|
590 | 665 | In [2]: IPython.__patched_cves__ |
|
591 | 666 | Out[2]: {'CVE-2022-21699'} |
|
592 | 667 | |
|
593 | 668 | In [3]: 'CVE-2022-21699' in IPython.__patched_cves__ |
|
594 | 669 | Out[3]: True |
|
595 | 670 | |
|
596 | 671 | Thus starting with this version: |
|
597 | 672 | |
|
598 | 673 | - The current working directory is not searched anymore for profiles or |
|
599 | 674 | configurations files. |
|
600 | 675 | - Added a ``__patched_cves__`` attribute (set of strings) to IPython module that contain |
|
601 | 676 | the list of fixed CVE. This is informational only. |
|
602 | 677 | |
|
603 | 678 | Further details can be read on the `GitHub Advisory <https://github.com/ipython/ipython/security/advisories/GHSA-pq7m-3gw7-gq5x>`__ |
|
604 | 679 | |
|
605 | 680 | |
|
606 | 681 | .. _version 8.0: |
|
607 | 682 | |
|
608 | 683 | IPython 8.0 |
|
609 | 684 | ----------- |
|
610 | 685 | |
|
611 | 686 | IPython 8.0 is bringing a large number of new features and improvements to both the |
|
612 | 687 | user of the terminal and of the kernel via Jupyter. The removal of compatibility |
|
613 | 688 | with an older version of Python is also the opportunity to do a couple of |
|
614 | 689 | performance improvements in particular with respect to startup time. |
|
615 | 690 | The 8.x branch started diverging from its predecessor around IPython 7.12 |
|
616 | 691 | (January 2020). |
|
617 | 692 | |
|
618 | 693 | This release contains 250+ pull requests, in addition to many of the features |
|
619 | 694 | and backports that have made it to the 7.x branch. Please see the |
|
620 | 695 | `8.0 milestone <https://github.com/ipython/ipython/milestone/73?closed=1>`__ for the full list of pull requests. |
|
621 | 696 | |
|
622 | 697 | Please feel free to send pull requests to update those notes after release, |
|
623 | 698 | I have likely forgotten a few things reviewing 250+ PRs. |
|
624 | 699 | |
|
625 | 700 | Dependencies changes/downstream packaging |
|
626 | 701 | ----------------------------------------- |
|
627 | 702 | |
|
628 | 703 | Most of our building steps have been changed to be (mostly) declarative |
|
629 | 704 | and follow PEP 517. We are trying to completely remove ``setup.py`` (:ghpull:`13238`) and are |
|
630 | 705 | looking for help to do so. |
|
631 | 706 | |
|
632 | 707 | - minimum supported ``traitlets`` version is now 5+ |
|
633 | 708 | - we now require ``stack_data`` |
|
634 | 709 | - minimal Python is now 3.8 |
|
635 | 710 | - ``nose`` is not a testing requirement anymore |
|
636 | 711 | - ``pytest`` replaces nose. |
|
637 | 712 | - ``iptest``/``iptest3`` cli entrypoints do not exist anymore. |
|
638 | 713 | - the minimum officially supported ``numpy`` version has been bumped, but this should |
|
639 | 714 | not have much effect on packaging. |
|
640 | 715 | |
|
641 | 716 | |
|
642 | 717 | Deprecation and removal |
|
643 | 718 | ----------------------- |
|
644 | 719 | |
|
645 | 720 | We removed almost all features, arguments, functions, and modules that were |
|
646 | 721 | marked as deprecated between IPython 1.0 and 5.0. As a reminder, 5.0 was released |
|
647 | 722 | in 2016, and 1.0 in 2013. Last release of the 5 branch was 5.10.0, in May 2020. |
|
648 | 723 | The few remaining deprecated features we left have better deprecation warnings |
|
649 | 724 | or have been turned into explicit errors for better error messages. |
|
650 | 725 | |
|
651 | 726 | I will use this occasion to add the following requests to anyone emitting a |
|
652 | 727 | deprecation warning: |
|
653 | 728 | |
|
654 | 729 | - Please add at least ``stacklevel=2`` so that the warning is emitted into the |
|
655 | 730 | caller context, and not the callee one. |
|
656 | 731 | - Please add **since which version** something is deprecated. |
|
657 | 732 | |
|
658 | 733 | As a side note, it is much easier to conditionally compare version |
|
659 | 734 | numbers rather than using ``try/except`` when functionality changes with a version. |
|
660 | 735 | |
|
661 | 736 | I won't list all the removed features here, but modules like ``IPython.kernel``, |
|
662 | 737 | which was just a shim module around ``ipykernel`` for the past 8 years, have been |
|
663 | 738 | removed, and so many other similar things that pre-date the name **Jupyter** |
|
664 | 739 | itself. |
|
665 | 740 | |
|
666 | 741 | We no longer need to add ``IPython.extensions`` to the PYTHONPATH because that is being |
|
667 | 742 | handled by ``load_extension``. |
|
668 | 743 | |
|
669 | 744 | We are also removing ``Cythonmagic``, ``sympyprinting`` and ``rmagic`` as they are now in |
|
670 | 745 | other packages and no longer need to be inside IPython. |
|
671 | 746 | |
|
672 | 747 | |
|
673 | 748 | Documentation |
|
674 | 749 | ------------- |
|
675 | 750 | |
|
676 | 751 | The majority of our docstrings have now been reformatted and automatically fixed by |
|
677 | 752 | the experimental `Vélin <https://pypi.org/project/velin/>`_ project to conform |
|
678 | 753 | to numpydoc. |
|
679 | 754 | |
|
680 | 755 | Type annotations |
|
681 | 756 | ---------------- |
|
682 | 757 | |
|
683 | 758 | While IPython itself is highly dynamic and can't be completely typed, many of |
|
684 | 759 | the functions now have type annotations, and part of the codebase is now checked |
|
685 | 760 | by mypy. |
|
686 | 761 | |
|
687 | 762 | |
|
688 | 763 | Featured changes |
|
689 | 764 | ---------------- |
|
690 | 765 | |
|
691 | 766 | Here is a features list of changes in IPython 8.0. This is of course non-exhaustive. |
|
692 | 767 | Please note as well that many features have been added in the 7.x branch as well |
|
693 | 768 | (and hence why you want to read the 7.x what's new notes), in particular |
|
694 | 769 | features contributed by QuantStack (with respect to debugger protocol and Xeus |
|
695 | 770 | Python), as well as many debugger features that I was pleased to implement as |
|
696 | 771 | part of my work at QuanSight and sponsored by DE Shaw. |
|
697 | 772 | |
|
698 | 773 | Traceback improvements |
|
699 | 774 | ~~~~~~~~~~~~~~~~~~~~~~ |
|
700 | 775 | |
|
701 | 776 | Previously, error tracebacks for errors happening in code cells were showing a |
|
702 | 777 | hash, the one used for compiling the Python AST:: |
|
703 | 778 | |
|
704 | 779 | In [1]: def foo(): |
|
705 | 780 | ...: return 3 / 0 |
|
706 | 781 | ...: |
|
707 | 782 | |
|
708 | 783 | In [2]: foo() |
|
709 | 784 | --------------------------------------------------------------------------- |
|
710 | 785 | ZeroDivisionError Traceback (most recent call last) |
|
711 | 786 | <ipython-input-2-c19b6d9633cf> in <module> |
|
712 | 787 | ----> 1 foo() |
|
713 | 788 | |
|
714 | 789 | <ipython-input-1-1595a74c32d5> in foo() |
|
715 | 790 | 1 def foo(): |
|
716 | 791 | ----> 2 return 3 / 0 |
|
717 | 792 | 3 |
|
718 | 793 | |
|
719 | 794 | ZeroDivisionError: division by zero |
|
720 | 795 | |
|
721 | 796 | The error traceback is now correctly formatted, showing the cell number in which the error happened:: |
|
722 | 797 | |
|
723 | 798 | In [1]: def foo(): |
|
724 | 799 | ...: return 3 / 0 |
|
725 | 800 | ...: |
|
726 | 801 | |
|
727 | 802 | Input In [2]: foo() |
|
728 | 803 | --------------------------------------------------------------------------- |
|
729 | 804 | ZeroDivisionError Traceback (most recent call last) |
|
730 | 805 | input In [2], in <module> |
|
731 | 806 | ----> 1 foo() |
|
732 | 807 | |
|
733 | 808 | Input In [1], in foo() |
|
734 | 809 | 1 def foo(): |
|
735 | 810 | ----> 2 return 3 / 0 |
|
736 | 811 | |
|
737 | 812 | ZeroDivisionError: division by zero |
|
738 | 813 | |
|
739 | 814 | The ``stack_data`` package has been integrated, which provides smarter information in the traceback; |
|
740 | 815 | in particular it will highlight the AST node where an error occurs which can help to quickly narrow down errors. |
|
741 | 816 | |
|
742 | 817 | For example in the following snippet:: |
|
743 | 818 | |
|
744 | 819 | def foo(i): |
|
745 | 820 | x = [[[0]]] |
|
746 | 821 | return x[0][i][0] |
|
747 | 822 | |
|
748 | 823 | |
|
749 | 824 | def bar(): |
|
750 | 825 | return foo(0) + foo( |
|
751 | 826 | 1 |
|
752 | 827 | ) + foo(2) |
|
753 | 828 | |
|
754 | 829 | |
|
755 | 830 | calling ``bar()`` would raise an ``IndexError`` on the return line of ``foo``, |
|
756 | 831 | and IPython 8.0 is capable of telling you where the index error occurs:: |
|
757 | 832 | |
|
758 | 833 | |
|
759 | 834 | IndexError |
|
760 | 835 | Input In [2], in <module> |
|
761 | 836 | ----> 1 bar() |
|
762 | 837 | ^^^^^ |
|
763 | 838 | |
|
764 | 839 | Input In [1], in bar() |
|
765 | 840 | 6 def bar(): |
|
766 | 841 | ----> 7 return foo(0) + foo( |
|
767 | 842 | ^^^^ |
|
768 | 843 | 8 1 |
|
769 | 844 | ^^^^^^^^ |
|
770 | 845 | 9 ) + foo(2) |
|
771 | 846 | ^^^^ |
|
772 | 847 | |
|
773 | 848 | Input In [1], in foo(i) |
|
774 | 849 | 1 def foo(i): |
|
775 | 850 | 2 x = [[[0]]] |
|
776 | 851 | ----> 3 return x[0][i][0] |
|
777 | 852 | ^^^^^^^ |
|
778 | 853 | |
|
779 | 854 | The corresponding locations marked here with ``^`` will show up highlighted in |
|
780 | 855 | the terminal and notebooks. |
|
781 | 856 | |
|
782 | 857 | Finally, a colon ``::`` and line number is appended after a filename in |
|
783 | 858 | traceback:: |
|
784 | 859 | |
|
785 | 860 | |
|
786 | 861 | ZeroDivisionError Traceback (most recent call last) |
|
787 | 862 | File ~/error.py:4, in <module> |
|
788 | 863 | 1 def f(): |
|
789 | 864 | 2 1/0 |
|
790 | 865 | ----> 4 f() |
|
791 | 866 | |
|
792 | 867 | File ~/error.py:2, in f() |
|
793 | 868 | 1 def f(): |
|
794 | 869 | ----> 2 1/0 |
|
795 | 870 | |
|
796 | 871 | Many terminals and editors have integrations enabling you to directly jump to the |
|
797 | 872 | relevant file/line when this syntax is used, so this small addition may have a high |
|
798 | 873 | impact on productivity. |
|
799 | 874 | |
|
800 | 875 | |
|
801 | 876 | Autosuggestions |
|
802 | 877 | ~~~~~~~~~~~~~~~ |
|
803 | 878 | |
|
804 | 879 | Autosuggestion is a very useful feature available in `fish <https://fishshell.com/>`__, `zsh <https://en.wikipedia.org/wiki/Z_shell>`__, and `prompt-toolkit <https://python-prompt-toolkit.readthedocs.io/en/master/pages/asking_for_input.html#auto-suggestion>`__. |
|
805 | 880 | |
|
806 | 881 | `Ptpython <https://github.com/prompt-toolkit/ptpython#ptpython>`__ allows users to enable this feature in |
|
807 | 882 | `ptpython/config.py <https://github.com/prompt-toolkit/ptpython/blob/master/examples/ptpython_config/config.py#L90>`__. |
|
808 | 883 | |
|
809 | 884 | This feature allows users to accept autosuggestions with ctrl e, ctrl f, |
|
810 | 885 | or right arrow as described below. |
|
811 | 886 | |
|
812 | 887 | 1. Start ipython |
|
813 | 888 | |
|
814 | 889 | .. image:: ../_images/8.0/auto_suggest_1_prompt_no_text.png |
|
815 | 890 | |
|
816 | 891 | 2. Run ``print("hello")`` |
|
817 | 892 | |
|
818 | 893 | .. image:: ../_images/8.0/auto_suggest_2_print_hello_suggest.png |
|
819 | 894 | |
|
820 | 895 | 3. start typing ``print`` again to see the autosuggestion |
|
821 | 896 | |
|
822 | 897 | .. image:: ../_images/8.0/auto_suggest_3_print_hello_suggest.png |
|
823 | 898 | |
|
824 | 899 | 4. Press ``ctrl-f``, or ``ctrl-e``, or ``right-arrow`` to accept the suggestion |
|
825 | 900 | |
|
826 | 901 | .. image:: ../_images/8.0/auto_suggest_4_print_hello.png |
|
827 | 902 | |
|
828 | 903 | You can also complete word by word: |
|
829 | 904 | |
|
830 | 905 | 1. Run ``def say_hello(): print("hello")`` |
|
831 | 906 | |
|
832 | 907 | .. image:: ../_images/8.0/auto_suggest_second_prompt.png |
|
833 | 908 | |
|
834 | 909 | 2. Start typing the first letter if ``def`` to see the autosuggestion |
|
835 | 910 | |
|
836 | 911 | .. image:: ../_images/8.0/auto_suggest_d_phantom.png |
|
837 | 912 | |
|
838 | 913 | 3. Press ``alt-f`` (or ``escape`` followed by ``f``), to accept the first word of the suggestion |
|
839 | 914 | |
|
840 | 915 | .. image:: ../_images/8.0/auto_suggest_def_phantom.png |
|
841 | 916 | |
|
842 | 917 | Importantly, this feature does not interfere with tab completion: |
|
843 | 918 | |
|
844 | 919 | 1. After running ``def say_hello(): print("hello")``, press d |
|
845 | 920 | |
|
846 | 921 | .. image:: ../_images/8.0/auto_suggest_d_phantom.png |
|
847 | 922 | |
|
848 | 923 | 2. Press Tab to start tab completion |
|
849 | 924 | |
|
850 | 925 | .. image:: ../_images/8.0/auto_suggest_d_completions.png |
|
851 | 926 | |
|
852 | 927 | 3A. Press Tab again to select the first option |
|
853 | 928 | |
|
854 | 929 | .. image:: ../_images/8.0/auto_suggest_def_completions.png |
|
855 | 930 | |
|
856 | 931 | 3B. Press ``alt f`` (``escape``, ``f``) to accept to accept the first word of the suggestion |
|
857 | 932 | |
|
858 | 933 | .. image:: ../_images/8.0/auto_suggest_def_phantom.png |
|
859 | 934 | |
|
860 | 935 | 3C. Press ``ctrl-f`` or ``ctrl-e`` to accept the entire suggestion |
|
861 | 936 | |
|
862 | 937 | .. image:: ../_images/8.0/auto_suggest_match_parens.png |
|
863 | 938 | |
|
864 | 939 | |
|
865 | 940 | Currently, autosuggestions are only shown in the emacs or vi insert editing modes: |
|
866 | 941 | |
|
867 | 942 | - The ctrl e, ctrl f, and alt f shortcuts work by default in emacs mode. |
|
868 | 943 | - To use these shortcuts in vi insert mode, you will have to create `custom keybindings in your config.py <https://github.com/mskar/setup/commit/2892fcee46f9f80ef7788f0749edc99daccc52f4/>`__. |
|
869 | 944 | |
|
870 | 945 | |
|
871 | 946 | Show pinfo information in ipdb using "?" and "??" |
|
872 | 947 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|
873 | 948 | |
|
874 | 949 | In IPDB, it is now possible to show the information about an object using "?" |
|
875 | 950 | and "??", in much the same way that it can be done when using the IPython prompt:: |
|
876 | 951 | |
|
877 | 952 | ipdb> partial? |
|
878 | 953 | Init signature: partial(self, /, *args, **kwargs) |
|
879 | 954 | Docstring: |
|
880 | 955 | partial(func, *args, **keywords) - new function with partial application |
|
881 | 956 | of the given arguments and keywords. |
|
882 | 957 | File: ~/.pyenv/versions/3.8.6/lib/python3.8/functools.py |
|
883 | 958 | Type: type |
|
884 | 959 | Subclasses: |
|
885 | 960 | |
|
886 | 961 | Previously, ``pinfo`` or ``pinfo2`` command had to be used for this purpose. |
|
887 | 962 | |
|
888 | 963 | |
|
889 | 964 | Autoreload 3 feature |
|
890 | 965 | ~~~~~~~~~~~~~~~~~~~~ |
|
891 | 966 | |
|
892 | 967 | Example: When an IPython session is run with the 'autoreload' extension loaded, |
|
893 | 968 | you will now have the option '3' to select, which means the following: |
|
894 | 969 | |
|
895 | 970 | 1. replicate all functionality from option 2 |
|
896 | 971 | 2. autoload all new funcs/classes/enums/globals from the module when they are added |
|
897 | 972 | 3. autoload all newly imported funcs/classes/enums/globals from external modules |
|
898 | 973 | |
|
899 | 974 | Try ``%autoreload 3`` in an IPython session after running ``%load_ext autoreload``. |
|
900 | 975 | |
|
901 | 976 | For more information please see the following unit test : ``extensions/tests/test_autoreload.py:test_autoload_newly_added_objects`` |
|
902 | 977 | |
|
903 | 978 | Auto formatting with black in the CLI |
|
904 | 979 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|
905 | 980 | |
|
906 | 981 | This feature was present in 7.x, but disabled by default. |
|
907 | 982 | |
|
908 | 983 | In 8.0, input was automatically reformatted with Black when black was installed. |
|
909 | 984 | This feature has been reverted for the time being. |
|
910 | 985 | You can re-enable it by setting ``TerminalInteractiveShell.autoformatter`` to ``"black"`` |
|
911 | 986 | |
|
912 | 987 | History Range Glob feature |
|
913 | 988 | ~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|
914 | 989 | |
|
915 | 990 | Previously, when using ``%history``, users could specify either |
|
916 | 991 | a range of sessions and lines, for example: |
|
917 | 992 | |
|
918 | 993 | .. code-block:: python |
|
919 | 994 | |
|
920 | 995 | ~8/1-~6/5 # see history from the first line of 8 sessions ago, |
|
921 | 996 | # to the fifth line of 6 sessions ago.`` |
|
922 | 997 | |
|
923 | 998 | Or users could specify a glob pattern: |
|
924 | 999 | |
|
925 | 1000 | .. code-block:: python |
|
926 | 1001 | |
|
927 | 1002 | -g <pattern> # glob ALL history for the specified pattern. |
|
928 | 1003 | |
|
929 | 1004 | However users could *not* specify both. |
|
930 | 1005 | |
|
931 | 1006 | If a user *did* specify both a range and a glob pattern, |
|
932 | 1007 | then the glob pattern would be used (globbing *all* history) *and the range would be ignored*. |
|
933 | 1008 | |
|
934 | 1009 | With this enhancement, if a user specifies both a range and a glob pattern, then the glob pattern will be applied to the specified range of history. |
|
935 | 1010 | |
|
936 | 1011 | Don't start a multi-line cell with sunken parenthesis |
|
937 | 1012 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|
938 | 1013 | |
|
939 | 1014 | From now on, IPython will not ask for the next line of input when given a single |
|
940 | 1015 | line with more closing than opening brackets. For example, this means that if |
|
941 | 1016 | you (mis)type ``]]`` instead of ``[]``, a ``SyntaxError`` will show up, instead of |
|
942 | 1017 | the ``...:`` prompt continuation. |
|
943 | 1018 | |
|
944 | 1019 | IPython shell for ipdb interact |
|
945 | 1020 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|
946 | 1021 | |
|
947 | 1022 | The ipdb ``interact`` starts an IPython shell instead of Python's built-in ``code.interact()``. |
|
948 | 1023 | |
|
949 | 1024 | Automatic Vi prompt stripping |
|
950 | 1025 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|
951 | 1026 | |
|
952 | 1027 | When pasting code into IPython, it will strip the leading prompt characters if |
|
953 | 1028 | there are any. For example, you can paste the following code into the console - |
|
954 | 1029 | it will still work, even though each line is prefixed with prompts (``In``, |
|
955 | 1030 | ``Out``):: |
|
956 | 1031 | |
|
957 | 1032 | In [1]: 2 * 2 == 4 |
|
958 | 1033 | Out[1]: True |
|
959 | 1034 | |
|
960 | 1035 | In [2]: print("This still works as pasted") |
|
961 | 1036 | |
|
962 | 1037 | |
|
963 | 1038 | Previously, this was not the case for the Vi-mode prompts:: |
|
964 | 1039 | |
|
965 | 1040 | In [1]: [ins] In [13]: 2 * 2 == 4 |
|
966 | 1041 | ...: Out[13]: True |
|
967 | 1042 | ...: |
|
968 | 1043 | File "<ipython-input-1-727bb88eaf33>", line 1 |
|
969 | 1044 | [ins] In [13]: 2 * 2 == 4 |
|
970 | 1045 | ^ |
|
971 | 1046 | SyntaxError: invalid syntax |
|
972 | 1047 | |
|
973 | 1048 | This is now fixed, and Vi prompt prefixes - ``[ins]`` and ``[nav]`` - are |
|
974 | 1049 | skipped just as the normal ``In`` would be. |
|
975 | 1050 | |
|
976 | 1051 | IPython shell can be started in the Vi mode using ``ipython --TerminalInteractiveShell.editing_mode=vi``, |
|
977 | 1052 | You should be able to change mode dynamically with ``%config TerminalInteractiveShell.editing_mode='vi'`` |
|
978 | 1053 | |
|
979 | 1054 | Empty History Ranges |
|
980 | 1055 | ~~~~~~~~~~~~~~~~~~~~ |
|
981 | 1056 | |
|
982 | 1057 | A number of magics that take history ranges can now be used with an empty |
|
983 | 1058 | range. These magics are: |
|
984 | 1059 | |
|
985 | 1060 | * ``%save`` |
|
986 | 1061 | * ``%load`` |
|
987 | 1062 | * ``%pastebin`` |
|
988 | 1063 | * ``%pycat`` |
|
989 | 1064 | |
|
990 | 1065 | Using them this way will make them take the history of the current session up |
|
991 | 1066 | to the point of the magic call (such that the magic itself will not be |
|
992 | 1067 | included). |
|
993 | 1068 | |
|
994 | 1069 | Therefore it is now possible to save the whole history to a file using |
|
995 | 1070 | ``%save <filename>``, load and edit it using ``%load`` (makes for a nice usage |
|
996 | 1071 | when followed with :kbd:`F2`), send it to `dpaste.org <http://dpast.org>`_ using |
|
997 | 1072 | ``%pastebin``, or view the whole thing syntax-highlighted with a single |
|
998 | 1073 | ``%pycat``. |
|
999 | 1074 | |
|
1000 | 1075 | |
|
1001 | 1076 | Windows timing implementation: Switch to process_time |
|
1002 | 1077 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|
1003 | 1078 | Timing on Windows, for example with ``%%time``, was changed from being based on ``time.perf_counter`` |
|
1004 | 1079 | (which counted time even when the process was sleeping) to being based on ``time.process_time`` instead |
|
1005 | 1080 | (which only counts CPU time). This brings it closer to the behavior on Linux. See :ghpull:`12984`. |
|
1006 | 1081 | |
|
1007 | 1082 | Miscellaneous |
|
1008 | 1083 | ~~~~~~~~~~~~~ |
|
1009 | 1084 | - Non-text formatters are not disabled in the terminal, which should simplify |
|
1010 | 1085 | writing extensions displaying images or other mimetypes in supporting terminals. |
|
1011 | 1086 | :ghpull:`12315` |
|
1012 | 1087 | - It is now possible to automatically insert matching brackets in Terminal IPython using the |
|
1013 | 1088 | ``TerminalInteractiveShell.auto_match=True`` option. :ghpull:`12586` |
|
1014 | 1089 | - We are thinking of deprecating the current ``%%javascript`` magic in favor of a better replacement. See :ghpull:`13376`. |
|
1015 | 1090 | - ``~`` is now expanded when part of a path in most magics :ghpull:`13385` |
|
1016 | 1091 | - ``%/%%timeit`` magic now adds a comma every thousands to make reading a long number easier :ghpull:`13379` |
|
1017 | 1092 | - ``"info"`` messages can now be customised to hide some fields :ghpull:`13343` |
|
1018 | 1093 | - ``collections.UserList`` now pretty-prints :ghpull:`13320` |
|
1019 | 1094 | - The debugger now has a persistent history, which should make it less |
|
1020 | 1095 | annoying to retype commands :ghpull:`13246` |
|
1021 | 1096 | - ``!pip`` ``!conda`` ``!cd`` or ``!ls`` are likely doing the wrong thing. We |
|
1022 | 1097 | now warn users if they use one of those commands. :ghpull:`12954` |
|
1023 | 1098 | - Make ``%precision`` work for ``numpy.float64`` type :ghpull:`12902` |
|
1024 | 1099 | |
|
1025 | 1100 | Re-added support for XDG config directories |
|
1026 | 1101 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|
1027 | 1102 | |
|
1028 | 1103 | XDG support through the years comes and goes. There is a tension between having |
|
1029 | 1104 | an identical location for configuration in all platforms versus having simple instructions. |
|
1030 | 1105 | After initial failures a couple of years ago, IPython was modified to automatically migrate XDG |
|
1031 | 1106 | config files back into ``~/.ipython``. That migration code has now been removed. |
|
1032 | 1107 | IPython now checks the XDG locations, so if you _manually_ move your config |
|
1033 | 1108 | files to your preferred location, IPython will not move them back. |
|
1034 | 1109 | |
|
1035 | 1110 | |
|
1036 | 1111 | Preparing for Python 3.10 |
|
1037 | 1112 | ------------------------- |
|
1038 | 1113 | |
|
1039 | 1114 | To prepare for Python 3.10, we have started working on removing reliance and |
|
1040 | 1115 | any dependency that is not compatible with Python 3.10. This includes migrating our |
|
1041 | 1116 | test suite to pytest and starting to remove nose. This also means that the |
|
1042 | 1117 | ``iptest`` command is now gone and all testing is via pytest. |
|
1043 | 1118 | |
|
1044 | 1119 | This was in large part thanks to the NumFOCUS Small Developer grant, which enabled us to |
|
1045 | 1120 | allocate \$4000 to hire `Nikita Kniazev (@Kojoley) <https://github.com/Kojoley>`_, |
|
1046 | 1121 | who did a fantastic job at updating our code base, migrating to pytest, pushing |
|
1047 | 1122 | our coverage, and fixing a large number of bugs. I highly recommend contacting |
|
1048 | 1123 | them if you need help with C++ and Python projects. |
|
1049 | 1124 | |
|
1050 | 1125 | You can find all relevant issues and PRs with `the SDG 2021 tag <https://github.com/ipython/ipython/issues?q=label%3A%22Numfocus+SDG+2021%22+>`__ |
|
1051 | 1126 | |
|
1052 | 1127 | Removing support for older Python versions |
|
1053 | 1128 | ------------------------------------------ |
|
1054 | 1129 | |
|
1055 | 1130 | |
|
1056 | 1131 | We are removing support for Python up through 3.7, allowing internal code to use the more |
|
1057 | 1132 | efficient ``pathlib`` and to make better use of type annotations. |
|
1058 | 1133 | |
|
1059 | 1134 | .. image:: ../_images/8.0/pathlib_pathlib_everywhere.jpg |
|
1060 | 1135 | :alt: "Meme image of Toy Story with Woody and Buzz, with the text 'pathlib, pathlib everywhere'" |
|
1061 | 1136 | |
|
1062 | 1137 | |
|
1063 | 1138 | We had about 34 PRs only to update some logic to update some functions from managing strings to |
|
1064 | 1139 | using Pathlib. |
|
1065 | 1140 | |
|
1066 | 1141 | The completer has also seen significant updates and now makes use of newer Jedi APIs, |
|
1067 | 1142 | offering faster and more reliable tab completion. |
|
1068 | 1143 | |
|
1069 | 1144 | Misc Statistics |
|
1070 | 1145 | --------------- |
|
1071 | 1146 | |
|
1072 | 1147 | Here are some numbers:: |
|
1073 | 1148 | |
|
1074 | 1149 | 7.x: 296 files, 12561 blank lines, 20282 comments, 35142 line of code. |
|
1075 | 1150 | 8.0: 252 files, 12053 blank lines, 19232 comments, 34505 line of code. |
|
1076 | 1151 | |
|
1077 | 1152 | $ git diff --stat 7.x...master | tail -1 |
|
1078 | 1153 | 340 files changed, 13399 insertions(+), 12421 deletions(-) |
|
1079 | 1154 | |
|
1080 | 1155 | We have commits from 162 authors, who contributed 1916 commits in 23 month, excluding merges (to not bias toward |
|
1081 | 1156 | maintainers pushing buttons).:: |
|
1082 | 1157 | |
|
1083 | 1158 | $ git shortlog -s --no-merges 7.x...master | sort -nr |
|
1084 | 1159 | 535 Matthias Bussonnier |
|
1085 | 1160 | 86 Nikita Kniazev |
|
1086 | 1161 | 69 Blazej Michalik |
|
1087 | 1162 | 49 Samuel Gaist |
|
1088 | 1163 | 27 Itamar Turner-Trauring |
|
1089 | 1164 | 18 Spas Kalaydzhisyki |
|
1090 | 1165 | 17 Thomas Kluyver |
|
1091 | 1166 | 17 Quentin Peter |
|
1092 | 1167 | 17 James Morris |
|
1093 | 1168 | 17 Artur Svistunov |
|
1094 | 1169 | 15 Bart Skowron |
|
1095 | 1170 | 14 Alex Hall |
|
1096 | 1171 | 13 rushabh-v |
|
1097 | 1172 | 13 Terry Davis |
|
1098 | 1173 | 13 Benjamin Ragan-Kelley |
|
1099 | 1174 | 8 martinRenou |
|
1100 | 1175 | 8 farisachugthai |
|
1101 | 1176 | 7 dswij |
|
1102 | 1177 | 7 Gal B |
|
1103 | 1178 | 7 Corentin Cadiou |
|
1104 | 1179 | 6 yuji96 |
|
1105 | 1180 | 6 Martin Skarzynski |
|
1106 | 1181 | 6 Justin Palmer |
|
1107 | 1182 | 6 Daniel Goldfarb |
|
1108 | 1183 | 6 Ben Greiner |
|
1109 | 1184 | 5 Sammy Al Hashemi |
|
1110 | 1185 | 5 Paul Ivanov |
|
1111 | 1186 | 5 Inception95 |
|
1112 | 1187 | 5 Eyenpi |
|
1113 | 1188 | 5 Douglas Blank |
|
1114 | 1189 | 5 Coco Mishra |
|
1115 | 1190 | 5 Bibo Hao |
|
1116 | 1191 | 5 André A. Gomes |
|
1117 | 1192 | 5 Ahmed Fasih |
|
1118 | 1193 | 4 takuya fujiwara |
|
1119 | 1194 | 4 palewire |
|
1120 | 1195 | 4 Thomas A Caswell |
|
1121 | 1196 | 4 Talley Lambert |
|
1122 | 1197 | 4 Scott Sanderson |
|
1123 | 1198 | 4 Ram Rachum |
|
1124 | 1199 | 4 Nick Muoh |
|
1125 | 1200 | 4 Nathan Goldbaum |
|
1126 | 1201 | 4 Mithil Poojary |
|
1127 | 1202 | 4 Michael T |
|
1128 | 1203 | 4 Jakub Klus |
|
1129 | 1204 | 4 Ian Castleden |
|
1130 | 1205 | 4 Eli Rykoff |
|
1131 | 1206 | 4 Ashwin Vishnu |
|
1132 | 1207 | 3 谭九鼎 |
|
1133 | 1208 | 3 sleeping |
|
1134 | 1209 | 3 Sylvain Corlay |
|
1135 | 1210 | 3 Peter Corke |
|
1136 | 1211 | 3 Paul Bissex |
|
1137 | 1212 | 3 Matthew Feickert |
|
1138 | 1213 | 3 Fernando Perez |
|
1139 | 1214 | 3 Eric Wieser |
|
1140 | 1215 | 3 Daniel Mietchen |
|
1141 | 1216 | 3 Aditya Sathe |
|
1142 | 1217 | 3 007vedant |
|
1143 | 1218 | 2 rchiodo |
|
1144 | 1219 | 2 nicolaslazo |
|
1145 | 1220 | 2 luttik |
|
1146 | 1221 | 2 gorogoroumaru |
|
1147 | 1222 | 2 foobarbyte |
|
1148 | 1223 | 2 bar-hen |
|
1149 | 1224 | 2 Theo Ouzhinski |
|
1150 | 1225 | 2 Strawkage |
|
1151 | 1226 | 2 Samreen Zarroug |
|
1152 | 1227 | 2 Pete Blois |
|
1153 | 1228 | 2 Meysam Azad |
|
1154 | 1229 | 2 Matthieu Ancellin |
|
1155 | 1230 | 2 Mark Schmitz |
|
1156 | 1231 | 2 Maor Kleinberger |
|
1157 | 1232 | 2 MRCWirtz |
|
1158 | 1233 | 2 Lumir Balhar |
|
1159 | 1234 | 2 Julien Rabinow |
|
1160 | 1235 | 2 Juan Luis Cano Rodríguez |
|
1161 | 1236 | 2 Joyce Er |
|
1162 | 1237 | 2 Jakub |
|
1163 | 1238 | 2 Faris A Chugthai |
|
1164 | 1239 | 2 Ethan Madden |
|
1165 | 1240 | 2 Dimitri Papadopoulos |
|
1166 | 1241 | 2 Diego Fernandez |
|
1167 | 1242 | 2 Daniel Shimon |
|
1168 | 1243 | 2 Coco Bennett |
|
1169 | 1244 | 2 Carlos Cordoba |
|
1170 | 1245 | 2 Boyuan Liu |
|
1171 | 1246 | 2 BaoGiang HoangVu |
|
1172 | 1247 | 2 Augusto |
|
1173 | 1248 | 2 Arthur Svistunov |
|
1174 | 1249 | 2 Arthur Moreira |
|
1175 | 1250 | 2 Ali Nabipour |
|
1176 | 1251 | 2 Adam Hackbarth |
|
1177 | 1252 | 1 richard |
|
1178 | 1253 | 1 linar-jether |
|
1179 | 1254 | 1 lbennett |
|
1180 | 1255 | 1 juacrumar |
|
1181 | 1256 | 1 gpotter2 |
|
1182 | 1257 | 1 digitalvirtuoso |
|
1183 | 1258 | 1 dalthviz |
|
1184 | 1259 | 1 Yonatan Goldschmidt |
|
1185 | 1260 | 1 Tomasz Kłoczko |
|
1186 | 1261 | 1 Tobias Bengfort |
|
1187 | 1262 | 1 Timur Kushukov |
|
1188 | 1263 | 1 Thomas |
|
1189 | 1264 | 1 Snir Broshi |
|
1190 | 1265 | 1 Shao Yang Hong |
|
1191 | 1266 | 1 Sanjana-03 |
|
1192 | 1267 | 1 Romulo Filho |
|
1193 | 1268 | 1 Rodolfo Carvalho |
|
1194 | 1269 | 1 Richard Shadrach |
|
1195 | 1270 | 1 Reilly Tucker Siemens |
|
1196 | 1271 | 1 Rakessh Roshan |
|
1197 | 1272 | 1 Piers Titus van der Torren |
|
1198 | 1273 | 1 PhanatosZou |
|
1199 | 1274 | 1 Pavel Safronov |
|
1200 | 1275 | 1 Paulo S. Costa |
|
1201 | 1276 | 1 Paul McCarthy |
|
1202 | 1277 | 1 NotWearingPants |
|
1203 | 1278 | 1 Naelson Douglas |
|
1204 | 1279 | 1 Michael Tiemann |
|
1205 | 1280 | 1 Matt Wozniski |
|
1206 | 1281 | 1 Markus Wageringel |
|
1207 | 1282 | 1 Marcus Wirtz |
|
1208 | 1283 | 1 Marcio Mazza |
|
1209 | 1284 | 1 Lumír 'Frenzy' Balhar |
|
1210 | 1285 | 1 Lightyagami1 |
|
1211 | 1286 | 1 Leon Anavi |
|
1212 | 1287 | 1 LeafyLi |
|
1213 | 1288 | 1 L0uisJ0shua |
|
1214 | 1289 | 1 Kyle Cutler |
|
1215 | 1290 | 1 Krzysztof Cybulski |
|
1216 | 1291 | 1 Kevin Kirsche |
|
1217 | 1292 | 1 KIU Shueng Chuan |
|
1218 | 1293 | 1 Jonathan Slenders |
|
1219 | 1294 | 1 Jay Qi |
|
1220 | 1295 | 1 Jake VanderPlas |
|
1221 | 1296 | 1 Iwan Briquemont |
|
1222 | 1297 | 1 Hussaina Begum Nandyala |
|
1223 | 1298 | 1 Gordon Ball |
|
1224 | 1299 | 1 Gabriel Simonetto |
|
1225 | 1300 | 1 Frank Tobia |
|
1226 | 1301 | 1 Erik |
|
1227 | 1302 | 1 Elliott Sales de Andrade |
|
1228 | 1303 | 1 Daniel Hahler |
|
1229 | 1304 | 1 Dan Green-Leipciger |
|
1230 | 1305 | 1 Dan Green |
|
1231 | 1306 | 1 Damian Yurzola |
|
1232 | 1307 | 1 Coon, Ethan T |
|
1233 | 1308 | 1 Carol Willing |
|
1234 | 1309 | 1 Brian Lee |
|
1235 | 1310 | 1 Brendan Gerrity |
|
1236 | 1311 | 1 Blake Griffin |
|
1237 | 1312 | 1 Bastian Ebeling |
|
1238 | 1313 | 1 Bartosz Telenczuk |
|
1239 | 1314 | 1 Ankitsingh6299 |
|
1240 | 1315 | 1 Andrew Port |
|
1241 | 1316 | 1 Andrew J. Hesford |
|
1242 | 1317 | 1 Albert Zhang |
|
1243 | 1318 | 1 Adam Johnson |
|
1244 | 1319 | |
|
1245 | 1320 | This does not, of course, represent non-code contributions, for which we are also grateful. |
|
1246 | 1321 | |
|
1247 | 1322 | |
|
1248 | 1323 | API Changes using Frappuccino |
|
1249 | 1324 | ----------------------------- |
|
1250 | 1325 | |
|
1251 | 1326 | This is an experimental exhaustive API difference using `Frappuccino <https://pypi.org/project/frappuccino/>`_ |
|
1252 | 1327 | |
|
1253 | 1328 | |
|
1254 | 1329 | The following items are new in IPython 8.0 :: |
|
1255 | 1330 | |
|
1256 | 1331 | + IPython.core.async_helpers.get_asyncio_loop() |
|
1257 | 1332 | + IPython.core.completer.Dict |
|
1258 | 1333 | + IPython.core.completer.Pattern |
|
1259 | 1334 | + IPython.core.completer.Sequence |
|
1260 | 1335 | + IPython.core.completer.__skip_doctest__ |
|
1261 | 1336 | + IPython.core.debugger.Pdb.precmd(self, line) |
|
1262 | 1337 | + IPython.core.debugger.__skip_doctest__ |
|
1263 | 1338 | + IPython.core.display.__getattr__(name) |
|
1264 | 1339 | + IPython.core.display.warn |
|
1265 | 1340 | + IPython.core.display_functions |
|
1266 | 1341 | + IPython.core.display_functions.DisplayHandle |
|
1267 | 1342 | + IPython.core.display_functions.DisplayHandle.display(self, obj, **kwargs) |
|
1268 | 1343 | + IPython.core.display_functions.DisplayHandle.update(self, obj, **kwargs) |
|
1269 | 1344 | + IPython.core.display_functions.__all__ |
|
1270 | 1345 | + IPython.core.display_functions.__builtins__ |
|
1271 | 1346 | + IPython.core.display_functions.__cached__ |
|
1272 | 1347 | + IPython.core.display_functions.__doc__ |
|
1273 | 1348 | + IPython.core.display_functions.__file__ |
|
1274 | 1349 | + IPython.core.display_functions.__loader__ |
|
1275 | 1350 | + IPython.core.display_functions.__name__ |
|
1276 | 1351 | + IPython.core.display_functions.__package__ |
|
1277 | 1352 | + IPython.core.display_functions.__spec__ |
|
1278 | 1353 | + IPython.core.display_functions.b2a_hex |
|
1279 | 1354 | + IPython.core.display_functions.clear_output(wait=False) |
|
1280 | 1355 | + IPython.core.display_functions.display(*objs, include='None', exclude='None', metadata='None', transient='None', display_id='None', raw=False, clear=False, **kwargs) |
|
1281 | 1356 | + IPython.core.display_functions.publish_display_data(data, metadata='None', source='<deprecated>', *, transient='None', **kwargs) |
|
1282 | 1357 | + IPython.core.display_functions.update_display(obj, *, display_id, **kwargs) |
|
1283 | 1358 | + IPython.core.extensions.BUILTINS_EXTS |
|
1284 | 1359 | + IPython.core.inputtransformer2.has_sunken_brackets(tokens) |
|
1285 | 1360 | + IPython.core.interactiveshell.Callable |
|
1286 | 1361 | + IPython.core.interactiveshell.__annotations__ |
|
1287 | 1362 | + IPython.core.ultratb.List |
|
1288 | 1363 | + IPython.core.ultratb.Tuple |
|
1289 | 1364 | + IPython.lib.pretty.CallExpression |
|
1290 | 1365 | + IPython.lib.pretty.CallExpression.factory(name) |
|
1291 | 1366 | + IPython.lib.pretty.RawStringLiteral |
|
1292 | 1367 | + IPython.lib.pretty.RawText |
|
1293 | 1368 | + IPython.terminal.debugger.TerminalPdb.do_interact(self, arg) |
|
1294 | 1369 | + IPython.terminal.embed.Set |
|
1295 | 1370 | |
|
1296 | 1371 | The following items have been removed (or moved to superclass):: |
|
1297 | 1372 | |
|
1298 | 1373 | - IPython.core.application.BaseIPythonApplication.initialize_subcommand |
|
1299 | 1374 | - IPython.core.completer.Sentinel |
|
1300 | 1375 | - IPython.core.completer.skip_doctest |
|
1301 | 1376 | - IPython.core.debugger.Tracer |
|
1302 | 1377 | - IPython.core.display.DisplayHandle |
|
1303 | 1378 | - IPython.core.display.DisplayHandle.display |
|
1304 | 1379 | - IPython.core.display.DisplayHandle.update |
|
1305 | 1380 | - IPython.core.display.b2a_hex |
|
1306 | 1381 | - IPython.core.display.clear_output |
|
1307 | 1382 | - IPython.core.display.display |
|
1308 | 1383 | - IPython.core.display.publish_display_data |
|
1309 | 1384 | - IPython.core.display.update_display |
|
1310 | 1385 | - IPython.core.excolors.Deprec |
|
1311 | 1386 | - IPython.core.excolors.ExceptionColors |
|
1312 | 1387 | - IPython.core.history.warn |
|
1313 | 1388 | - IPython.core.hooks.late_startup_hook |
|
1314 | 1389 | - IPython.core.hooks.pre_run_code_hook |
|
1315 | 1390 | - IPython.core.hooks.shutdown_hook |
|
1316 | 1391 | - IPython.core.interactiveshell.InteractiveShell.init_deprecation_warnings |
|
1317 | 1392 | - IPython.core.interactiveshell.InteractiveShell.init_readline |
|
1318 | 1393 | - IPython.core.interactiveshell.InteractiveShell.write |
|
1319 | 1394 | - IPython.core.interactiveshell.InteractiveShell.write_err |
|
1320 | 1395 | - IPython.core.interactiveshell.get_default_colors |
|
1321 | 1396 | - IPython.core.interactiveshell.removed_co_newlocals |
|
1322 | 1397 | - IPython.core.magics.execution.ExecutionMagics.profile_missing_notice |
|
1323 | 1398 | - IPython.core.magics.script.PIPE |
|
1324 | 1399 | - IPython.core.prefilter.PrefilterManager.init_transformers |
|
1325 | 1400 | - IPython.core.release.classifiers |
|
1326 | 1401 | - IPython.core.release.description |
|
1327 | 1402 | - IPython.core.release.keywords |
|
1328 | 1403 | - IPython.core.release.long_description |
|
1329 | 1404 | - IPython.core.release.name |
|
1330 | 1405 | - IPython.core.release.platforms |
|
1331 | 1406 | - IPython.core.release.url |
|
1332 | 1407 | - IPython.core.ultratb.VerboseTB.format_records |
|
1333 | 1408 | - IPython.core.ultratb.find_recursion |
|
1334 | 1409 | - IPython.core.ultratb.findsource |
|
1335 | 1410 | - IPython.core.ultratb.fix_frame_records_filenames |
|
1336 | 1411 | - IPython.core.ultratb.inspect_error |
|
1337 | 1412 | - IPython.core.ultratb.is_recursion_error |
|
1338 | 1413 | - IPython.core.ultratb.with_patch_inspect |
|
1339 | 1414 | - IPython.external.__all__ |
|
1340 | 1415 | - IPython.external.__builtins__ |
|
1341 | 1416 | - IPython.external.__cached__ |
|
1342 | 1417 | - IPython.external.__doc__ |
|
1343 | 1418 | - IPython.external.__file__ |
|
1344 | 1419 | - IPython.external.__loader__ |
|
1345 | 1420 | - IPython.external.__name__ |
|
1346 | 1421 | - IPython.external.__package__ |
|
1347 | 1422 | - IPython.external.__path__ |
|
1348 | 1423 | - IPython.external.__spec__ |
|
1349 | 1424 | - IPython.kernel.KernelConnectionInfo |
|
1350 | 1425 | - IPython.kernel.__builtins__ |
|
1351 | 1426 | - IPython.kernel.__cached__ |
|
1352 | 1427 | - IPython.kernel.__warningregistry__ |
|
1353 | 1428 | - IPython.kernel.pkg |
|
1354 | 1429 | - IPython.kernel.protocol_version |
|
1355 | 1430 | - IPython.kernel.protocol_version_info |
|
1356 | 1431 | - IPython.kernel.src |
|
1357 | 1432 | - IPython.kernel.version_info |
|
1358 | 1433 | - IPython.kernel.warn |
|
1359 | 1434 | - IPython.lib.backgroundjobs |
|
1360 | 1435 | - IPython.lib.backgroundjobs.BackgroundJobBase |
|
1361 | 1436 | - IPython.lib.backgroundjobs.BackgroundJobBase.run |
|
1362 | 1437 | - IPython.lib.backgroundjobs.BackgroundJobBase.traceback |
|
1363 | 1438 | - IPython.lib.backgroundjobs.BackgroundJobExpr |
|
1364 | 1439 | - IPython.lib.backgroundjobs.BackgroundJobExpr.call |
|
1365 | 1440 | - IPython.lib.backgroundjobs.BackgroundJobFunc |
|
1366 | 1441 | - IPython.lib.backgroundjobs.BackgroundJobFunc.call |
|
1367 | 1442 | - IPython.lib.backgroundjobs.BackgroundJobManager |
|
1368 | 1443 | - IPython.lib.backgroundjobs.BackgroundJobManager.flush |
|
1369 | 1444 | - IPython.lib.backgroundjobs.BackgroundJobManager.new |
|
1370 | 1445 | - IPython.lib.backgroundjobs.BackgroundJobManager.remove |
|
1371 | 1446 | - IPython.lib.backgroundjobs.BackgroundJobManager.result |
|
1372 | 1447 | - IPython.lib.backgroundjobs.BackgroundJobManager.status |
|
1373 | 1448 | - IPython.lib.backgroundjobs.BackgroundJobManager.traceback |
|
1374 | 1449 | - IPython.lib.backgroundjobs.__builtins__ |
|
1375 | 1450 | - IPython.lib.backgroundjobs.__cached__ |
|
1376 | 1451 | - IPython.lib.backgroundjobs.__doc__ |
|
1377 | 1452 | - IPython.lib.backgroundjobs.__file__ |
|
1378 | 1453 | - IPython.lib.backgroundjobs.__loader__ |
|
1379 | 1454 | - IPython.lib.backgroundjobs.__name__ |
|
1380 | 1455 | - IPython.lib.backgroundjobs.__package__ |
|
1381 | 1456 | - IPython.lib.backgroundjobs.__spec__ |
|
1382 | 1457 | - IPython.lib.kernel.__builtins__ |
|
1383 | 1458 | - IPython.lib.kernel.__cached__ |
|
1384 | 1459 | - IPython.lib.kernel.__doc__ |
|
1385 | 1460 | - IPython.lib.kernel.__file__ |
|
1386 | 1461 | - IPython.lib.kernel.__loader__ |
|
1387 | 1462 | - IPython.lib.kernel.__name__ |
|
1388 | 1463 | - IPython.lib.kernel.__package__ |
|
1389 | 1464 | - IPython.lib.kernel.__spec__ |
|
1390 | 1465 | - IPython.lib.kernel.__warningregistry__ |
|
1391 | 1466 | - IPython.paths.fs_encoding |
|
1392 | 1467 | - IPython.terminal.debugger.DEFAULT_BUFFER |
|
1393 | 1468 | - IPython.terminal.debugger.cursor_in_leading_ws |
|
1394 | 1469 | - IPython.terminal.debugger.emacs_insert_mode |
|
1395 | 1470 | - IPython.terminal.debugger.has_selection |
|
1396 | 1471 | - IPython.terminal.debugger.vi_insert_mode |
|
1397 | 1472 | - IPython.terminal.interactiveshell.DISPLAY_BANNER_DEPRECATED |
|
1398 | 1473 | - IPython.terminal.ipapp.TerminalIPythonApp.parse_command_line |
|
1399 | 1474 | - IPython.testing.test |
|
1400 | 1475 | - IPython.utils.contexts.NoOpContext |
|
1401 | 1476 | - IPython.utils.io.IOStream |
|
1402 | 1477 | - IPython.utils.io.IOStream.close |
|
1403 | 1478 | - IPython.utils.io.IOStream.write |
|
1404 | 1479 | - IPython.utils.io.IOStream.writelines |
|
1405 | 1480 | - IPython.utils.io.__warningregistry__ |
|
1406 | 1481 | - IPython.utils.io.atomic_writing |
|
1407 | 1482 | - IPython.utils.io.stderr |
|
1408 | 1483 | - IPython.utils.io.stdin |
|
1409 | 1484 | - IPython.utils.io.stdout |
|
1410 | 1485 | - IPython.utils.io.unicode_std_stream |
|
1411 | 1486 | - IPython.utils.path.get_ipython_cache_dir |
|
1412 | 1487 | - IPython.utils.path.get_ipython_dir |
|
1413 | 1488 | - IPython.utils.path.get_ipython_module_path |
|
1414 | 1489 | - IPython.utils.path.get_ipython_package_dir |
|
1415 | 1490 | - IPython.utils.path.locate_profile |
|
1416 | 1491 | - IPython.utils.path.unquote_filename |
|
1417 | 1492 | - IPython.utils.py3compat.PY2 |
|
1418 | 1493 | - IPython.utils.py3compat.PY3 |
|
1419 | 1494 | - IPython.utils.py3compat.buffer_to_bytes |
|
1420 | 1495 | - IPython.utils.py3compat.builtin_mod_name |
|
1421 | 1496 | - IPython.utils.py3compat.cast_bytes |
|
1422 | 1497 | - IPython.utils.py3compat.getcwd |
|
1423 | 1498 | - IPython.utils.py3compat.isidentifier |
|
1424 | 1499 | - IPython.utils.py3compat.u_format |
|
1425 | 1500 | |
|
1426 | 1501 | The following signatures differ between 7.x and 8.0:: |
|
1427 | 1502 | |
|
1428 | 1503 | - IPython.core.completer.IPCompleter.unicode_name_matches(self, text) |
|
1429 | 1504 | + IPython.core.completer.IPCompleter.unicode_name_matches(text) |
|
1430 | 1505 | |
|
1431 | 1506 | - IPython.core.completer.match_dict_keys(keys, prefix, delims) |
|
1432 | 1507 | + IPython.core.completer.match_dict_keys(keys, prefix, delims, extra_prefix='None') |
|
1433 | 1508 | |
|
1434 | 1509 | - IPython.core.interactiveshell.InteractiveShell.object_inspect_mime(self, oname, detail_level=0) |
|
1435 | 1510 | + IPython.core.interactiveshell.InteractiveShell.object_inspect_mime(self, oname, detail_level=0, omit_sections='()') |
|
1436 | 1511 | |
|
1437 | 1512 | - IPython.core.interactiveshell.InteractiveShell.set_hook(self, name, hook, priority=50, str_key='None', re_key='None', _warn_deprecated=True) |
|
1438 | 1513 | + IPython.core.interactiveshell.InteractiveShell.set_hook(self, name, hook, priority=50, str_key='None', re_key='None') |
|
1439 | 1514 | |
|
1440 | 1515 | - IPython.core.oinspect.Inspector.info(self, obj, oname='', formatter='None', info='None', detail_level=0) |
|
1441 | 1516 | + IPython.core.oinspect.Inspector.info(self, obj, oname='', info='None', detail_level=0) |
|
1442 | 1517 | |
|
1443 | 1518 | - IPython.core.oinspect.Inspector.pinfo(self, obj, oname='', formatter='None', info='None', detail_level=0, enable_html_pager=True) |
|
1444 | 1519 | + IPython.core.oinspect.Inspector.pinfo(self, obj, oname='', formatter='None', info='None', detail_level=0, enable_html_pager=True, omit_sections='()') |
|
1445 | 1520 | |
|
1446 | 1521 | - IPython.core.profiledir.ProfileDir.copy_config_file(self, config_file, path='None', overwrite=False) |
|
1447 | 1522 | + IPython.core.profiledir.ProfileDir.copy_config_file(self, config_file, path, overwrite=False) |
|
1448 | 1523 | |
|
1449 | 1524 | - IPython.core.ultratb.VerboseTB.format_record(self, frame, file, lnum, func, lines, index) |
|
1450 | 1525 | + IPython.core.ultratb.VerboseTB.format_record(self, frame_info) |
|
1451 | 1526 | |
|
1452 | 1527 | - IPython.terminal.embed.InteractiveShellEmbed.mainloop(self, local_ns='None', module='None', stack_depth=0, display_banner='None', global_ns='None', compile_flags='None') |
|
1453 | 1528 | + IPython.terminal.embed.InteractiveShellEmbed.mainloop(self, local_ns='None', module='None', stack_depth=0, compile_flags='None') |
|
1454 | 1529 | |
|
1455 | 1530 | - IPython.terminal.embed.embed(**kwargs) |
|
1456 | 1531 | + IPython.terminal.embed.embed(*, header='', compile_flags='None', **kwargs) |
|
1457 | 1532 | |
|
1458 | 1533 | - IPython.terminal.interactiveshell.TerminalInteractiveShell.interact(self, display_banner='<object object at 0xffffff>') |
|
1459 | 1534 | + IPython.terminal.interactiveshell.TerminalInteractiveShell.interact(self) |
|
1460 | 1535 | |
|
1461 | 1536 | - IPython.terminal.interactiveshell.TerminalInteractiveShell.mainloop(self, display_banner='<object object at 0xffffff>') |
|
1462 | 1537 | + IPython.terminal.interactiveshell.TerminalInteractiveShell.mainloop(self) |
|
1463 | 1538 | |
|
1464 | 1539 | - IPython.utils.path.get_py_filename(name, force_win32='None') |
|
1465 | 1540 | + IPython.utils.path.get_py_filename(name) |
|
1466 | 1541 | |
|
1467 | 1542 | The following are new attributes (that might be inherited):: |
|
1468 | 1543 | |
|
1469 | 1544 | + IPython.core.completer.IPCompleter.unicode_names |
|
1470 | 1545 | + IPython.core.debugger.InterruptiblePdb.precmd |
|
1471 | 1546 | + IPython.core.debugger.Pdb.precmd |
|
1472 | 1547 | + IPython.core.ultratb.AutoFormattedTB.has_colors |
|
1473 | 1548 | + IPython.core.ultratb.ColorTB.has_colors |
|
1474 | 1549 | + IPython.core.ultratb.FormattedTB.has_colors |
|
1475 | 1550 | + IPython.core.ultratb.ListTB.has_colors |
|
1476 | 1551 | + IPython.core.ultratb.SyntaxTB.has_colors |
|
1477 | 1552 | + IPython.core.ultratb.TBTools.has_colors |
|
1478 | 1553 | + IPython.core.ultratb.VerboseTB.has_colors |
|
1479 | 1554 | + IPython.terminal.debugger.TerminalPdb.do_interact |
|
1480 | 1555 | + IPython.terminal.debugger.TerminalPdb.precmd |
|
1481 | 1556 | |
|
1482 | 1557 | The following attribute/methods have been removed:: |
|
1483 | 1558 | |
|
1484 | 1559 | - IPython.core.application.BaseIPythonApplication.deprecated_subcommands |
|
1485 | 1560 | - IPython.core.ultratb.AutoFormattedTB.format_records |
|
1486 | 1561 | - IPython.core.ultratb.ColorTB.format_records |
|
1487 | 1562 | - IPython.core.ultratb.FormattedTB.format_records |
|
1488 | 1563 | - IPython.terminal.embed.InteractiveShellEmbed.init_deprecation_warnings |
|
1489 | 1564 | - IPython.terminal.embed.InteractiveShellEmbed.init_readline |
|
1490 | 1565 | - IPython.terminal.embed.InteractiveShellEmbed.write |
|
1491 | 1566 | - IPython.terminal.embed.InteractiveShellEmbed.write_err |
|
1492 | 1567 | - IPython.terminal.interactiveshell.TerminalInteractiveShell.init_deprecation_warnings |
|
1493 | 1568 | - IPython.terminal.interactiveshell.TerminalInteractiveShell.init_readline |
|
1494 | 1569 | - IPython.terminal.interactiveshell.TerminalInteractiveShell.write |
|
1495 | 1570 | - IPython.terminal.interactiveshell.TerminalInteractiveShell.write_err |
|
1496 | 1571 | - IPython.terminal.ipapp.LocateIPythonApp.deprecated_subcommands |
|
1497 | 1572 | - IPython.terminal.ipapp.LocateIPythonApp.initialize_subcommand |
|
1498 | 1573 | - IPython.terminal.ipapp.TerminalIPythonApp.deprecated_subcommands |
|
1499 | 1574 | - IPython.terminal.ipapp.TerminalIPythonApp.initialize_subcommand |
@@ -1,115 +1,116 b'' | |||
|
1 | 1 | [metadata] |
|
2 | 2 | name = ipython |
|
3 | 3 | version = attr: IPython.core.release.__version__ |
|
4 | 4 | url = https://ipython.org |
|
5 | 5 | description = IPython: Productive Interactive Computing |
|
6 | 6 | long_description_content_type = text/x-rst |
|
7 | 7 | long_description = file: long_description.rst |
|
8 | 8 | license_file = LICENSE |
|
9 | 9 | project_urls = |
|
10 | 10 | Documentation = https://ipython.readthedocs.io/ |
|
11 | 11 | Funding = https://numfocus.org/ |
|
12 | 12 | Source = https://github.com/ipython/ipython |
|
13 | 13 | Tracker = https://github.com/ipython/ipython/issues |
|
14 | 14 | keywords = Interactive, Interpreter, Shell, Embedding |
|
15 | 15 | platforms = Linux, Mac OSX, Windows |
|
16 | 16 | classifiers = |
|
17 | 17 | Framework :: IPython |
|
18 | 18 | Framework :: Jupyter |
|
19 | 19 | Intended Audience :: Developers |
|
20 | 20 | Intended Audience :: Science/Research |
|
21 | 21 | License :: OSI Approved :: BSD License |
|
22 | 22 | Programming Language :: Python |
|
23 | 23 | Programming Language :: Python :: 3 |
|
24 | 24 | Programming Language :: Python :: 3 :: Only |
|
25 | 25 | Topic :: System :: Shells |
|
26 | 26 | |
|
27 | 27 | [options] |
|
28 | 28 | packages = find: |
|
29 | 29 | python_requires = >=3.8 |
|
30 | 30 | zip_safe = False |
|
31 | 31 | install_requires = |
|
32 | 32 | appnope; sys_platform == "darwin" |
|
33 | 33 | backcall |
|
34 | 34 | colorama; sys_platform == "win32" |
|
35 | 35 | decorator |
|
36 | 36 | jedi>=0.16 |
|
37 | 37 | matplotlib-inline |
|
38 | 38 | pexpect>4.3; sys_platform != "win32" |
|
39 | 39 | pickleshare |
|
40 | 40 | prompt_toolkit>=3.0.30,<3.1.0,!=3.0.37 |
|
41 | 41 | pygments>=2.4.0 |
|
42 | 42 | stack_data |
|
43 | 43 | traitlets>=5 |
|
44 | typing_extensions ; python_version<'3.10' | |
|
44 | 45 | |
|
45 | 46 | [options.extras_require] |
|
46 | 47 | black = |
|
47 | 48 | black |
|
48 | 49 | doc = |
|
49 | 50 | ipykernel |
|
50 | 51 | setuptools>=18.5 |
|
51 | 52 | sphinx>=1.3 |
|
52 | 53 | sphinx-rtd-theme |
|
53 | 54 | docrepr |
|
54 | 55 | matplotlib |
|
55 | 56 | stack_data |
|
56 | 57 | pytest<7 |
|
57 | 58 | typing_extensions |
|
58 | 59 | %(test)s |
|
59 | 60 | kernel = |
|
60 | 61 | ipykernel |
|
61 | 62 | nbconvert = |
|
62 | 63 | nbconvert |
|
63 | 64 | nbformat = |
|
64 | 65 | nbformat |
|
65 | 66 | notebook = |
|
66 | 67 | ipywidgets |
|
67 | 68 | notebook |
|
68 | 69 | parallel = |
|
69 | 70 | ipyparallel |
|
70 | 71 | qtconsole = |
|
71 | 72 | qtconsole |
|
72 | 73 | terminal = |
|
73 | 74 | test = |
|
74 | 75 | pytest<7.1 |
|
75 | 76 | pytest-asyncio |
|
76 | 77 | testpath |
|
77 | 78 | test_extra = |
|
78 | 79 | %(test)s |
|
79 | 80 | curio |
|
80 | 81 | matplotlib!=3.2.0 |
|
81 | 82 | nbformat |
|
82 | 83 | numpy>=1.21 |
|
83 | 84 | pandas |
|
84 | 85 | trio |
|
85 | 86 | all = |
|
86 | 87 | %(black)s |
|
87 | 88 | %(doc)s |
|
88 | 89 | %(kernel)s |
|
89 | 90 | %(nbconvert)s |
|
90 | 91 | %(nbformat)s |
|
91 | 92 | %(notebook)s |
|
92 | 93 | %(parallel)s |
|
93 | 94 | %(qtconsole)s |
|
94 | 95 | %(terminal)s |
|
95 | 96 | %(test_extra)s |
|
96 | 97 | %(test)s |
|
97 | 98 | |
|
98 | 99 | [options.packages.find] |
|
99 | 100 | exclude = |
|
100 | 101 | setupext |
|
101 | 102 | |
|
102 | 103 | [options.package_data] |
|
103 | 104 | IPython = py.typed |
|
104 | 105 | IPython.core = profile/README* |
|
105 | 106 | IPython.core.tests = *.png, *.jpg, daft_extension/*.py |
|
106 | 107 | IPython.lib.tests = *.wav |
|
107 | 108 | IPython.testing.plugin = *.txt |
|
108 | 109 | |
|
109 | 110 | [velin] |
|
110 | 111 | ignore_patterns = |
|
111 | 112 | IPython/core/tests |
|
112 | 113 | IPython/testing |
|
113 | 114 | |
|
114 | 115 | [tool.black] |
|
115 | 116 | exclude = 'timing\.py' |
General Comments 0
You need to be logged in to leave comments.
Login now