ninia / jep

Embed Python in Java
Other
1.3k stars 147 forks source link

Cannot invoke function with full import #422

Open Daniel-Alievsky opened 2 years ago

Daniel-Alievsky commented 2 years ago

I have Python module tests.SimpleJepTestA in a package "tests". This module contains a simple function:

def testSimplest():
    return "Hello"

I import this module by its full name, without "from" or "as": interp.exec("import tests.SimpleJepTestA"); I prefer this form, because it is a system code, and I don't want to pollute the namespace. Then I can freely execute this function: interp.exec("tests.SimpleJepTestA.testSimplest()") But I cannot invoke it: interp.invoke("tests.SimpleJepTestA.testSimplest") It shows an exception <class 'AttributeError'>: module 'tests' has no attribute 'SimpleJepTestA.testSimplest'

It seems like a bug. There is a workaround, which works normally: interp.getValue("tests.SimpleJepTestA.testSimplest", PyCallable.class).call() What is the problem with the simple "invoke" method?

There is no such a problem if I use aliases like interp.exec("import tests.SimpleJepTestA as MyTest")

Daniel-Alievsky commented 2 years ago

Maybe the problem is in your function pyembed_invoke_method_as ? I see here char* dot = strchr(cname, '.'); It searches for the first dot, but in this situation we need the last.