System assigns result in invalid syntax
See original GitHub issueIf I have a cell with
flake8_version = !flake8 --version
flake8_version
, then this executes fine.
However, the equivalent Python representation of it from jupytext is:
# %%
flake8_version = !flake8 --version
flake8_version
which is invalid syntax (and not something I could run flake8
on 😄 )
I’m bringing this up because in https://github.com/mwouts/jupytext/issues/781 you commented
magic commands are always commented out by default
but this one wasn’t commented out.
From a quick glance at the source code, it looks like magics are detected using regular expressions - have you considered using IPython’s TransformerManager
and then ast-parsing instead? I’m happy to help out with this if you want greater support for magic detection (at least, in Python notebooks)
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Invalid Syntax in Python: Common Reasons for SyntaxError
Misusing the Assignment Operator ( = ) ... The first example tries to assign the value 5 to the len() call. The SyntaxError...
Read more >python - Why do I get the syntax error "SyntaxError: invalid ...
, I get an error message: SyntaxError: invalid syntax . Pmin , Pmax , w , fi1 and fi2 have all been assigned...
Read more >SyntaxError: invalid syntax - Python Morsels
Python's "invalid syntax" error message comes up often, especially when you're first learning Python. What usually causes this error and how can you...
Read more >Syntaxerror: invalid syntax (solved) - Classical Finance
Why am I getting syntax errors · A missing assignment operator · Python keyword error · Opening and closing symbols · Not escaping...
Read more >I wrote the following code and got the following error message.
I've entered these two lines multiple times now with the same result. ... To assign a value to a variable, use the following...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Other than the official does, I don’t have any extra documentation (other than the docstrings in
src/black/handle_ipynb_magics.py
from https://github.com/psf/black/pull/2357/files )Agreed - but you can keep the commented out magics using this approach. You just use
TransformerManager
to detect where the magics are, then you “extract” the magic usingast.parse
, then you comment / uncomment - so the script would still look like the notebookIn https://github.com/psf/black/pull/2357 I replace the magics with randomly generated tokens, but they could just as easily be replaced with commented-out versions of themselves
I’ll put something together to demonstrate when I get a chance