-
-
Notifications
You must be signed in to change notification settings - Fork 8.8k
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| """ | ||
| categories: Types,Exception | ||
| description: The ``__traceback__`` attribute of exceptions is a simple list of tuples. | ||
| cause: MicroPython is optimised to reduce code size. | ||
| workaround: Check the type of ``__traceback__`` before using it. | ||
| """ | ||
|
|
||
|
|
||
| def foo(): | ||
| 1 / 0 | ||
|
|
||
|
|
||
| try: | ||
| foo() | ||
| except Exception as e: | ||
| print(e.__traceback__) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| # This comment allows test runners like run_script_on_remote_target | ||
| # to safely prepend a line of code without messing up line numbers. | ||
|
|
||
|
|
||
| def foo(): | ||
| 1 / 0 | ||
|
|
||
|
|
||
| def normalize(filename): | ||
| if filename == "<stdin>": | ||
| return "traceback.py" | ||
| return filename.split("/")[-1] | ||
|
|
||
|
|
||
| try: | ||
| foo() | ||
| except Exception as e: | ||
| tb = e.__traceback__ | ||
| for t in tb: | ||
| print("%s:%d" % (normalize(t[0]), t[1]), *t[2:]) | ||
| e.__traceback__ = None | ||
| print(e.__traceback__) | ||
| try: | ||
| e.args = 77 | ||
| except AttributeError: | ||
| print("setting args not allowed") | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| traceback.py:6 foo | ||
| traceback.py:16 <module> | ||
| [] | ||
| setting args not allowed |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -80,6 +80,7 @@ | |
| "misc/sys_settrace_features.py", | ||
| "misc/sys_settrace_generator.py", | ||
| "misc/sys_settrace_loop.py", | ||
| "micropython/traceback.py", | ||
| ), | ||
| } | ||
|
|
||
|
|
@@ -108,6 +109,8 @@ | |
| "micropython/schedule.py", | ||
| # These require sys.exc_info(). | ||
| "misc/sys_exc_info.py", | ||
| # These require exception tracebacks. | ||
| "micropython/traceback.py", | ||
| # These require sys.settrace(). | ||
| "misc/sys_settrace_cov.py", | ||
| "misc/sys_settrace_features.py", | ||
|
|
@@ -125,9 +128,7 @@ | |
| "stress/list_sort.py", # watchdog kicks in because it takes too long | ||
| ), | ||
| "minimal": ( | ||
| "basics/class_inplace_op.py", # all special methods not supported | ||
| "basics/subclass_native_init.py", # native subclassing corner cases not support | ||
| "micropython/opt_level.py", # don't assume line numbers are stored | ||
| "micropython/traceback.py", # no line numbers, no list[N:] syntax | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please don't remove these (see comment below). |
||
| ), | ||
| "nrf": ( | ||
| "basics/io_buffered_writer.py", | ||
|
|
@@ -827,6 +828,8 @@ def run_tests(pyb, tests, args, result_dir, num_threads=1): | |
|
|
||
| # Skip platform-specific tests. | ||
| skip_tests.update(platform_tests_to_skip.get(args.platform, ())) | ||
| if args.build == "minimal": | ||
| skip_tests.update(platform_tests_to_skip.get(args.build, ())) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I understand why you made this change, but it's not the right approach. We should not mix up the platform with the build. If really needed we can add a |
||
|
|
||
| # Some tests are known to fail on 64-bit machines | ||
| if pyb is None and platform.architecture()[0] == "64bit": | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest calling this test
exc_traceback.py.And then adding (or changing this comment) to briefly mention what it's testing, eg
Test values of BaseException.__traceback__which are MicroPython specific".