Skip to content
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

Use of """ in docstrings does not work in org src block #561

Open
fraricci opened this issue Oct 17, 2024 · 1 comment
Open

Use of """ in docstrings does not work in org src block #561

fraricci opened this issue Oct 17, 2024 · 1 comment

Comments

@fraricci
Copy link

fraricci commented Oct 17, 2024

I wanted to share this issue I recently found. Not sure this has been discussed already.

Here a simple example of code that generate an error:

#+begin_src jupyter-python
class Example():
    """docstring"""

#+end_src

#+RESULTS:
:RESULTS:
# [goto error]
:   Cell In[155], line 5
:     get_ipython().run_cell(r"""class Example():
:                            ^
: SyntaxError: invalid syntax. Perhaps you forgot a comma?
:END:

The way I found to avoid this is to replace """ with '''.
I believe the use of """ is recommended or at least very common.
Is there a way to fix this? Or there's something broken in my org config.

Thanks!

@fraricci
Copy link
Author

testing a little more I found that a possible cause of this is setting the option :dir (which I had set in the #+PROPERTY: in the example above).

#+begin_src jupyter-python :dir ./ 
class example():
    """docstring"""

print("test")
#+end_src

#+RESULTS:
:RESULTS:
# [goto error]
:   Cell In[22], line 5
:     get_ipython().run_cell(r"""class example():
:                            ^
: SyntaxError: invalid syntax. Perhaps you forgot a comma?
:END:

without :dir, it works fine

#+begin_src jupyter-python
class example():
    """docstring"""

print("ciao")
#+end_src

#+RESULTS:
: ciao

Also, this happens in similar way:

#+begin_src jupyter-python :dir ./
var = "test"
#+end_src

#+RESULTS:
:RESULTS:
# [goto error]
:   Cell In[32], line 5
:     get_ipython().run_cell(r"""var = "test"""")
:                                              ^
: SyntaxError: unterminated string literal (detected at line 5)
:END:

here, removing the :dir flag works, but also adding a newline or a space after the var = "test" fixes the issue even keeping the :dir flag

#+begin_src jupyter-python :dir ./
var = "test"

#+end_src

#+RESULTS:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant