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

Syntax error with first line comment pattern #...#? #1295

Closed
JMLuther opened this issue Nov 2, 2022 · 4 comments
Closed

Syntax error with first line comment pattern #...#? #1295

JMLuther opened this issue Nov 2, 2022 · 4 comments

Comments

@JMLuther
Copy link

JMLuther commented Nov 2, 2022

When adapting someone else's code, I discovered that any command with a comment pattern of # something #? at the end of the first line will error.

This seems to be a reticulate bug to be aware of, easily fixable by avoiding this comment pattern.
This behavior does not occur in the python REPL.

Examples:

test = {"A": 1,  # Invalid comment pattern #?
            "B":2}
    # Error in py_run_string_impl(code, local, convert) : 
    #     File "<string>", line 1
    #     help("test = {"A": 1,  #  Invalid comment pattern  #")
    #          ^^^^^^^^^^^
    # SyntaxError: invalid syntax. Perhaps you forgot a comma?
    
[1,2,3] # test #?
    # No Python documentation found for '[1,2,3] # test #'.
    # Use help() to get the interactive help utility.
    # Use help(str) for help on the str class.

If on a multiline command, this only occurs if the comment is on the first line. The following commands work fine, no error, so it seems to be the "?" character after a second #:

test = {"A": 1,  # valid comment #X
        "B":2}
test = {"A": 1,  # valid comment #/
        "B":2}


test = {"A": 1,  # valid comment 
        "B":2}   #?

test = {"A": 1,  # valid comment 
        "B":2}   # #?

[1,2,3] # test
[1,2,3] # ? test

Running on Windows, R 4.2.1, python 3.10.6, reticulate 1.26

@kevinushey
Copy link
Collaborator

Most likely coming from here:

reticulate/R/repl.R

Lines 252 to 258 in a1d7f7f

# similar handling for help requests postfixed with '?'
if (grepl("[?]\\s*$", trimmed)) {
replaced <- sub("[?]\\s*$", "", trimmed)
code <- sprintf("help(\"%s\")", replaced)
py_run_string(code)
return()
}

We should be stricter in detecting + handling postfix ? usages.

@dfalbel dfalbel assigned dfalbel and unassigned dfalbel Aug 11, 2023
@dfalbel
Copy link
Member

dfalbel commented Aug 11, 2023

I can no longer reproduce this with v1.31. I believe this has been fixed in reticulate v1.29 as v1.28 is the last version I can observe this behavior.

@dfalbel dfalbel closed this as completed Aug 11, 2023
@t-kalinowski
Copy link
Member

This was fixed with #1070 (comment) I think.

@JMLuther
Copy link
Author

I confirmed on my computer it no longer errors. Thanks!

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

4 participants