Skip to content

Syntax Error #293

Description

@crackedbeefcake

I run this little snipped

    let code_input = format!("def sum(a, b):\n  return a + b");
    let code_test = format!("\nresult = sum(1, 2)\nprint(result)",);
    let code = format!(
        r#"{}
{}"#,
        code_input, code_test
    );

    let result: Result<PyObject, PyErr> = py.eval(&code, None, None);

    println!("CODE: \n{}", code);
    println!("OUTPUT: \n{result:#?}\n");

And this is the result:

CODE: 
def sum(a, b):
  return a + b

result = sum(1, 2)
print(result)

OUTPUT: 
Err(
    PyErr {
        ptype: <class 'SyntaxError'>,
        pvalue: Some(
            ('invalid syntax', ('<string>', 1, 1, 'def sum(a, b):\n', 1, 4)),
        ),
        ptraceback: None,
    },
)

Where is the invalid syntax coming from?
if i copy paste the code into a python repl, it executes.

def sum(a, b):
  return a + b

result = sum(1, 2)
print(result)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions