-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
py/modsys.c: Add sys._exc_traceback. #11244
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
2b52b5b
to
e7a799e
Compare
Code size report:
|
Codecov Report
📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more @@ Coverage Diff @@
## master #11244 +/- ##
==========================================
- Coverage 98.50% 98.44% -0.06%
==========================================
Files 155 155
Lines 20549 20561 +12
==========================================
Hits 20241 20241
- Misses 308 320 +12
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
First thing to ask is how would one do this in CPython? Then we need to consider if it's worth the cost (code size) and whether it should be guarded by a config macro. I would say yes it should be, but then at what level would it be enabled, eg |
You can get this info in CPython is like this: import traceback
def foo():
1/0
try:
foo()
except Exception as e:
tb = e.__traceback__
while tb is not None:
print("====")
print(" filename: " + str(tb.tb_frame.f_code.co_filename))
print(" line: " + str(tb.tb_lineno))
print(" name: " + str(tb.tb_frame.f_code.co_name))
tb = tb.tb_next This involves at least three different classes:
The Python standard library also comes with a traceback module that introduces more classes. MicroPython implements a minimal traceback module. CPython does not have |
I changed it so that this function is only enabled by default if |
14c94e2
to
4b5c6c3
Compare
This makes it easier to provide custom formatting of exception stack traces, e.g. to make them fit on a tiny display. This is an experimental function that exposes internal details of MicroPython and it might change in the future. Signed-off-by: David (Pololu) <dev-david@pololu.com>
4b5c6c3
to
d872e6e
Compare
This is an automated heads-up that we've just merged a Pull Request See #13763 A search suggests this PR might apply the STATIC macro to some C code. If it Although this is an automated message, feel free to @-reply to me directly if |
This new function makes it easier to provide custom formatting of exception stack traces, for example to make them fit on a tiny 16x8-character display. (Without this, I think you'd have to call
sys.print_exception
, somehow get the output as a string, and then scrape information from that string.)I'm thinking of this as an experimental function that exposes internal details of MicroPython and therefore might change in the future. That's why it has the underscore in the name.
Here is an example of its output:
The regular output from
sys.print_exception
for the same exception is:Both outputs were generated by the following script:
Is this the right approach for getting info about exception stack traces? I'd be happy to change the name, change the output format, add tests, or add documentation.