Show More
@@ -24,14 +24,17 import traceback | |||
|
24 | 24 | from pprint import pformat |
|
25 | 25 | from pathlib import Path |
|
26 | 26 | |
|
27 | import builtins as builtin_mod | |
|
28 | ||
|
27 | 29 | from IPython.core import ultratb |
|
30 | from IPython.core.application import Application | |
|
28 | 31 | from IPython.core.release import author_email |
|
29 | 32 | from IPython.utils.sysinfo import sys_info |
|
30 | from IPython.utils.py3compat import input | |
|
31 | 33 | |
|
32 | 34 | from IPython.core.release import __version__ as version |
|
33 | 35 | |
|
34 | from typing import Optional | |
|
36 | from typing import Optional, Dict | |
|
37 | import types | |
|
35 | 38 | |
|
36 | 39 | #----------------------------------------------------------------------------- |
|
37 | 40 | # Code |
@@ -84,7 +87,7 Extra-detailed tracebacks for bug-reporting purposes can be enabled via: | |||
|
84 | 87 | """ |
|
85 | 88 | |
|
86 | 89 | |
|
87 |
class CrashHandler |
|
|
90 | class CrashHandler: | |
|
88 | 91 | """Customizable crash handlers for IPython applications. |
|
89 | 92 | |
|
90 | 93 | Instances of this class provide a :meth:`__call__` method which can be |
@@ -95,10 +98,11 class CrashHandler(object): | |||
|
95 | 98 | |
|
96 | 99 | message_template = _default_message_template |
|
97 | 100 | section_sep = '\n\n'+'*'*75+'\n\n' |
|
101 | info: Dict[str, Optional[str]] | |
|
98 | 102 | |
|
99 | 103 | def __init__( |
|
100 | 104 | self, |
|
101 | app, | |
|
105 | app: Application, | |
|
102 | 106 | contact_name: Optional[str] = None, |
|
103 | 107 | contact_email: Optional[str] = None, |
|
104 | 108 | bug_tracker: Optional[str] = None, |
@@ -142,8 +146,12 class CrashHandler(object): | |||
|
142 | 146 | bug_tracker = bug_tracker, |
|
143 | 147 | crash_report_fname = self.crash_report_fname) |
|
144 | 148 | |
|
145 | ||
|
146 | def __call__(self, etype, evalue, etb): | |
|
149 | def __call__( | |
|
150 | self, | |
|
151 | etype: type[BaseException], | |
|
152 | evalue: BaseException, | |
|
153 | etb: types.TracebackType, | |
|
154 | ) -> None: | |
|
147 | 155 | """Handle an exception, call for compatible with sys.excepthook""" |
|
148 | 156 | |
|
149 | 157 | # do not allow the crash handler to be called twice without reinstalling it |
@@ -156,20 +164,22 class CrashHandler(object): | |||
|
156 | 164 | |
|
157 | 165 | # Use this ONLY for developer debugging (keep commented out for release) |
|
158 | 166 | #color_scheme = 'Linux' # dbg |
|
159 | try: | |
|
160 | rptdir = self.app.ipython_dir | |
|
161 | except: | |
|
167 | ipython_dir = getattr(self.app, "ipython_dir", None) | |
|
168 | if ipython_dir is not None: | |
|
169 | assert isinstance(ipython_dir, str) | |
|
170 | rptdir = Path(ipython_dir) | |
|
171 | else: | |
|
162 | 172 | rptdir = Path.cwd() |
|
163 |
if |
|
|
173 | if not rptdir.is_dir(): | |
|
164 | 174 | rptdir = Path.cwd() |
|
165 | 175 | report_name = rptdir / self.crash_report_fname |
|
166 | 176 | # write the report filename into the instance dict so it can get |
|
167 | 177 | # properly expanded out in the user message template |
|
168 | self.crash_report_fname = report_name | |
|
169 |
self.info[ |
|
|
178 | self.crash_report_fname = str(report_name) | |
|
179 | self.info["crash_report_fname"] = str(report_name) | |
|
170 | 180 | TBhandler = ultratb.VerboseTB( |
|
171 | 181 | color_scheme=color_scheme, |
|
172 |
long_header= |
|
|
182 | long_header=True, | |
|
173 | 183 | call_pdb=self.call_pdb, |
|
174 | 184 | ) |
|
175 | 185 | if self.call_pdb: |
@@ -195,11 +205,11 class CrashHandler(object): | |||
|
195 | 205 | print(self.message_template.format(**self.info), file=sys.stderr) |
|
196 | 206 | |
|
197 | 207 | # Construct report on disk |
|
198 | report.write(self.make_report(traceback)) | |
|
208 | report.write(self.make_report(str(traceback))) | |
|
199 | 209 | |
|
200 | input("Hit <Enter> to quit (your terminal may close):") | |
|
210 | builtin_mod.input("Hit <Enter> to quit (your terminal may close):") | |
|
201 | 211 | |
|
202 | def make_report(self,traceback): | |
|
212 | def make_report(self, traceback: str) -> str: | |
|
203 | 213 | """Return a string containing a crash report.""" |
|
204 | 214 | |
|
205 | 215 | sec_sep = self.section_sep |
@@ -211,8 +221,8 class CrashHandler(object): | |||
|
211 | 221 | try: |
|
212 | 222 | config = pformat(self.app.config) |
|
213 | 223 | rpt_add(sec_sep) |
|
214 |
rpt_add( |
|
|
215 |
rpt_add( |
|
|
224 | rpt_add("Application name: %s\n\n" % self.app.name) | |
|
225 | rpt_add("Current user configuration structure:\n\n") | |
|
216 | 226 | rpt_add(config) |
|
217 | 227 | except: |
|
218 | 228 | pass |
@@ -221,7 +231,9 class CrashHandler(object): | |||
|
221 | 231 | return ''.join(report) |
|
222 | 232 | |
|
223 | 233 | |
|
224 |
def crash_handler_lite( |
|
|
234 | def crash_handler_lite( | |
|
235 | etype: type[BaseException], evalue: BaseException, tb: types.TracebackType | |
|
236 | ) -> None: | |
|
225 | 237 | """a light excepthook, adding a small message to the usual traceback""" |
|
226 | 238 | traceback.print_exception(etype, evalue, tb) |
|
227 | 239 |
@@ -99,7 +99,7 def get_sys_info() -> dict: | |||
|
99 | 99 | path = Path(__file__, "..").resolve().parent |
|
100 | 100 | return pkg_info(str(path)) |
|
101 | 101 | |
|
102 | def sys_info(): | |
|
102 | def sys_info() -> str: | |
|
103 | 103 | """Return useful information about IPython and the system, as a string. |
|
104 | 104 | |
|
105 | 105 | Examples |
@@ -137,17 +137,29 exclude = [ | |||
|
137 | 137 | 'IPython/utils/_process_win32.py', |
|
138 | 138 | 'IPython/utils/path.py', |
|
139 | 139 | ] |
|
140 |
|
|
|
140 | # check_untyped_defs = true | |
|
141 | # disallow_untyped_calls = true | |
|
142 | # disallow_untyped_decorators = true | |
|
141 | 143 | # ignore_errors = false |
|
142 | 144 | # ignore_missing_imports = false |
|
143 | # disallow_untyped_calls = true | |
|
144 | 145 | disallow_incomplete_defs = true |
|
145 |
|
|
|
146 | # disallow_untyped_decorators = true | |
|
146 | disallow_untyped_defs = true | |
|
147 | 147 | warn_redundant_casts = true |
|
148 | 148 | |
|
149 | 149 | [[tool.mypy.overrides]] |
|
150 | 150 | module = [ |
|
151 | "IPython.core.crashhandler", | |
|
152 | ] | |
|
153 | check_untyped_defs = true | |
|
154 | disallow_incomplete_defs = true | |
|
155 | disallow_untyped_calls = true | |
|
156 | disallow_untyped_decorators = true | |
|
157 | disallow_untyped_defs = true | |
|
158 | ignore_errors = false | |
|
159 | ignore_missing_imports = false | |
|
160 | ||
|
161 | [[tool.mypy.overrides]] | |
|
162 | module = [ | |
|
151 | 163 | "IPython.utils.text", |
|
152 | 164 | ] |
|
153 | 165 | disallow_untyped_defs = true |
@@ -165,6 +177,7 disallow_incomplete_defs = false | |||
|
165 | 177 | check_untyped_defs = false |
|
166 | 178 | disallow_untyped_decorators = false |
|
167 | 179 | |
|
180 | ||
|
168 | 181 | # gloabl ignore error |
|
169 | 182 | [[tool.mypy.overrides]] |
|
170 | 183 | module = [ |
@@ -177,7 +190,6 module = [ | |||
|
177 | 190 | "IPython.core.compilerop", |
|
178 | 191 | "IPython.core.completer", |
|
179 | 192 | "IPython.core.completerlib", |
|
180 | "IPython.core.crashhandler", | |
|
181 | 193 | "IPython.core.debugger", |
|
182 | 194 | "IPython.core.display", |
|
183 | 195 | "IPython.core.display_functions", |
General Comments 0
You need to be logged in to leave comments.
Login now