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

Exporting a method with a different name than its declaration #408

Open
RevolvingMadness opened this issue Jul 10, 2024 · 4 comments
Open

Comments

@RevolvingMadness
Copy link

Let's say I have a Java class:

class Foo {
    public void bar() {
        System.out.println("bar");
    }
}

I want to access that bar method in python but with a different name. I swear a while ago I could do:

@HostAccess.Export(name = "barMethod")
public void bar() {
    System.out.println("bar");
}

But now the name field doesn't exist?

So then in Python it would be called with barMethod instead of bar.

@chumer
Copy link
Member

chumer commented Jul 15, 2024

That is currently not possible. Can you elaborate a bit on why you would want to do that instead of declaring a method with the new name?

@RevolvingMadness
Copy link
Author

I have a typing library in python that allows IntelliSense to function and I want to use snake_case because that is what you are supposed to use with methods. In Java you're supposed to use camelCase for method names. So the declaration in Java would be barMethod the method in Python would be bar_method. I can just declare the methods in java as bar_method or the methods in Python as barMethod but I was just wondering if this was possible.

@timfel
Copy link
Member

timfel commented Oct 12, 2024

@RevolvingMadness if you want to map Java methods to Python for idiomatic reasons, you might be interested in a new GraalPy specific feature in the latest release: https://github.com/oracle/graalpython/blob/master/docs/user/Interoperability.md#interop-types

This allows you to write some Python code to map methods for specific Java types

@timfel
Copy link
Member

timfel commented Oct 14, 2024

Sorry, I confused myself, and this feature is actually only master so far and will be in the upcoming release.

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

3 participants