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