Skip to content

escaped parentheses cause issues in reticulate REPL #1259

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

Open
kevinushey opened this issue Aug 17, 2022 · 2 comments
Open

escaped parentheses cause issues in reticulate REPL #1259

kevinushey opened this issue Aug 17, 2022 · 2 comments

Comments

@kevinushey
Copy link
Collaborator

For example, if I try to submit the following code to the reticulate REPL:

while False:
  '\('

I see:

>>> while False:
...   '\('
IndentationError: expected an indented block after 'while' statement on line 1 (<string>, line 1)
IndentationError: unexpected indent (<string>, line 1)

Alternatively;

> reticulate::repl_python(input = "while False:\n\t'\\('\n")
Python 3.10.4 (C:/Users/kevin/AppData/Local/Programs/Python/Python310/python.exe)
Reticulate 1.25 REPL -- A Python interpreter in R.
Enter 'exit' or 'quit' to exit the REPL and return to R.
>>>  while False:
...  	'\('
IndentationError: expected an indented block after 'while' statement on line 1 (<string>, line 1)
IndentationError: unexpected indent (<string>, line 1)
@kevinushey
Copy link
Collaborator Author

It looks like there's an underlying error that's getting swallowed here:

debug: ready <- tryCatch(compiler(code), condition = identity)
Browse[2]> code
[1] "while False:\n\t'\\('"
Browse[2]> n
debug: if (is.null(ready)) return()
Browse[2]> ready
<Rcpp::exception in py_call_impl(callable, dots$args, dots$keywords):   File "<input>", line 2
    	'\('
    	^^^^
SyntaxError: invalid escape sequence '\('
>

But yet, I see the following in IDLE:

>>> '\('
    '\\('
>>> while False:
... 	'\('
... 	
    SyntaxError: invalid escape sequence '\('

So this seems like a strange issue in Python itself?

@kevinushey
Copy link
Collaborator Author

Filed python/cpython#96052 upstream; in theory, reticulate could try to work around this but I'm not sure if it's worth the effort.

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