Skip to content

BUG: Fix bug with traceback with SyntaxError#1301

Merged
larsoner merged 4 commits intosphinx-gallery:masterfrom
larsoner:syntax
May 2, 2024
Merged

BUG: Fix bug with traceback with SyntaxError#1301
larsoner merged 4 commits intosphinx-gallery:masterfrom
larsoner:syntax

Conversation

@larsoner
Copy link
Copy Markdown
Contributor

@larsoner larsoner commented May 1, 2024

Fixes an incorrect traceback:

    ../examples/inverse/read_inverse.py failed leaving traceback:

    Traceback (most recent call last):
      File "/home/circleci/project/examples/inverse/read_inverse.py", line 26
        meg_path = data_path / "MEG" / "sample"
                                               ^

to:

../examples/inverse/read_inverse.py unexpectedly failed to execute correctly:

    Traceback (most recent call last):
      File "/home/larsoner/python/sphinx-gallery/sphinx_gallery/gen_rst.py", line 961, in execute_code_block
        code_ast = compile(
                   ^^^^^^^^
      File "/home/larsoner/python/mne-python/examples/inverse/read_inverse.py", line 43
        print(f"Number of vertices on the right hemisphere: {len(src[1]["rr"])}")
                                                                         ^^
    SyntaxError: f-string: unmatched '['

By just prepending "\n"'s when trying to compile the code.

Also cleans up some code since we're 3.8+ now.

Draft until I add a regression test.

@larsoner larsoner marked this pull request as draft May 1, 2024 00:44
@larsoner larsoner added the bug label May 1, 2024
@larsoner larsoner marked this pull request as ready for review May 1, 2024 13:05
@larsoner
Copy link
Copy Markdown
Contributor Author

larsoner commented May 1, 2024

Okay, test added that fails on master but passes on this PR, ready for review/merge @lucyleeow !

Copy link
Copy Markdown
Contributor

@lucyleeow lucyleeow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for the clean ups!

Co-authored-by: Lucy Liu <jliu176@gmail.com>
@larsoner larsoner enabled auto-merge (squash) May 2, 2024 14:17
@larsoner larsoner merged commit d780cae into sphinx-gallery:master May 2, 2024
@larsoner larsoner deleted the syntax branch May 2, 2024 14:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants