##// END OF EJS Templates
even more types
Matthias Bussonnier -
Show More
@@ -64,7 +64,8 b" magic_run_re = re.compile(r'.*(\\.ipy|\\.ipynb|\\.py[w]?)$')"
64 64 # Local utilities
65 65 #-----------------------------------------------------------------------------
66 66
67 def module_list(path):
67
68 def module_list(path: str) -> List[str]:
68 69 """
69 70 Return the list containing the names of the modules available in the given
70 71 folder.
@@ -80,7 +81,7 b' def module_list(path):'
80 81 # Build a list of all files in the directory and all files
81 82 # in its subdirectories. For performance reasons, do not
82 83 # recurse more than one level into subdirectories.
83 files = []
84 files: List[str] = []
84 85 for root, dirs, nondirs in os.walk(path, followlinks=True):
85 86 subdir = root[len(path)+1:]
86 87 if subdir:
@@ -91,8 +92,8 b' def module_list(path):'
91 92
92 93 else:
93 94 try:
94 files = list(zipimporter(path)._files.keys())
95 except:
95 files = list(zipimporter(path)._files.keys()) # type: ignore
96 except Exception:
96 97 files = []
97 98
98 99 # Build a list of modules which match the import_re regex.
@@ -194,7 +195,9 b' def try_import(mod: str, only_modules=False) -> List[str]:'
194 195
195 196 if m_is_init:
196 197 file_ = m.__file__
197 completions.extend(module_list(os.path.dirname(file_)))
198 file_path = os.path.dirname(file_) # type: ignore
199 if file_path is not None:
200 completions.extend(module_list(file_path))
198 201 completions_set = {c for c in completions if isinstance(c, str)}
199 202 completions_set.discard('__init__')
200 203 return list(completions_set)
@@ -24,6 +24,8 b' from traitlets import List'
24 24 # This used to be defined here - it is imported for backwards compatibility
25 25 from .display_functions import publish_display_data
26 26
27 import typing as t
28
27 29 #-----------------------------------------------------------------------------
28 30 # Main payload class
29 31 #-----------------------------------------------------------------------------
@@ -103,9 +105,9 b' class DisplayPublisher(Configurable):'
103 105 rather than creating a new output.
104 106 """
105 107
106 handlers = {}
108 handlers: t.Dict = {}
107 109 if self.shell is not None:
108 handlers = getattr(self.shell, 'mime_renderers', {})
110 handlers = getattr(self.shell, "mime_renderers", {})
109 111
110 112 for mime, handler in handlers.items():
111 113 if mime in data:
@@ -125,11 +127,20 b' class DisplayPublisher(Configurable):'
125 127
126 128 class CapturingDisplayPublisher(DisplayPublisher):
127 129 """A DisplayPublisher that stores"""
128 outputs = List()
129 130
130 def publish(self, data, metadata=None, source=None, *, transient=None, update=False):
131 self.outputs.append({'data':data, 'metadata':metadata,
132 'transient':transient, 'update':update})
131 outputs: List = List()
132
133 def publish(
134 self, data, metadata=None, source=None, *, transient=None, update=False
135 ):
136 self.outputs.append(
137 {
138 "data": data,
139 "metadata": metadata,
140 "transient": transient,
141 "update": update,
142 }
143 )
133 144
134 145 def clear_output(self, wait=False):
135 146 super(CapturingDisplayPublisher, self).clear_output(wait)
@@ -31,8 +31,7 b' import sys'
31 31 import tokenize
32 32 import warnings
33 33
34 from typing import List, Tuple, Union, Optional
35 from typing_extensions import Self
34 from typing import List, Tuple, Union, Optional, TYPE_CHECKING
36 35 from types import CodeType
37 36
38 37 from IPython.core.inputtransformer import (leading_indent,
@@ -53,6 +52,8 b' from IPython.core.inputtransformer import (ESC_SHELL, ESC_SH_CAP, ESC_HELP,'
53 52 ESC_HELP2, ESC_MAGIC, ESC_MAGIC2,
54 53 ESC_QUOTE, ESC_QUOTE2, ESC_PAREN, ESC_SEQUENCES)
55 54
55 if TYPE_CHECKING:
56 from typing_extensions import Self
56 57 #-----------------------------------------------------------------------------
57 58 # Utilities
58 59 #-----------------------------------------------------------------------------
@@ -26,6 +26,8 b' from ..utils.text import dedent'
26 26 from traitlets import Bool, Dict, Instance, observe
27 27 from logging import error
28 28
29 import typing as t
30
29 31 #-----------------------------------------------------------------------------
30 32 # Globals
31 33 #-----------------------------------------------------------------------------
@@ -36,7 +38,7 b' from logging import error'
36 38 # access to the class when they run. See for more details:
37 39 # http://stackoverflow.com/questions/2366713/can-a-python-decorator-of-an-instance-method-access-the-class
38 40
39 magics = dict(line={}, cell={})
41 magics: t.Dict = dict(line={}, cell={})
40 42
41 43 magic_kinds = ('line', 'cell')
42 44 magic_spec = ('line', 'cell', 'line_cell')
@@ -1,4 +1,3 b''
1 # -*- coding: utf-8 -*-
2 1 """
3 2 Python advanced pretty printer. This pretty printer is intended to
4 3 replace the old `pprint` python module which does not allow developers
@@ -108,6 +107,8 b' from warnings import warn'
108 107 from IPython.utils.decorators import undoc
109 108 from IPython.utils.py3compat import PYPY
110 109
110 from typing import Dict
111
111 112 __all__ = ['pretty', 'pprint', 'PrettyPrinter', 'RepresentationPrinter',
112 113 'for_type', 'for_type_by_name', 'RawText', 'RawStringLiteral', 'CallExpression']
113 114
@@ -807,6 +808,7 b' def _exception_pprint(obj, p, cycle):'
807 808
808 809
809 810 #: the exception base
811 _exception_base: type
810 812 try:
811 813 _exception_base = BaseException
812 814 except NameError:
@@ -848,8 +850,8 b' _type_pprinters[range] = _repr_pprint'
848 850 _type_pprinters[bytes] = _repr_pprint
849 851
850 852 #: printers for types specified by name
851 _deferred_type_pprinters = {
852 }
853 _deferred_type_pprinters: Dict = {}
854
853 855
854 856 def for_type(typ, func):
855 857 """
@@ -17,14 +17,8 b' exclude = ['
17 17 'PyColorize.py',
18 18 '_process_win32_controller.py',
19 19 'IPython/core/application.py',
20 'IPython/core/completerlib.py',
21 'IPython/core/displaypub.py',
22 #'IPython/core/interactiveshell.py',
23 'IPython/core/magic.py',
24 20 'IPython/core/profileapp.py',
25 # 'IPython/core/ultratb.py',
26 21 'IPython/lib/deepreload.py',
27 'IPython/lib/pretty.py',
28 22 'IPython/sphinxext/ipython_directive.py',
29 23 'IPython/terminal/ipapp.py',
30 24 'IPython/utils/_process_win32.py',
General Comments 0
You need to be logged in to leave comments. Login now