Skip to content

@PythonCall annotation for functions #617

@lars-reimann

Description

@lars-reimann

Is your feature request related to a problem?

For some functions, we might want to offer a different interface than Python offers. For example, we might want to replace the Python code ', '.join([1, 2]) with [1, 2].join(', ').

Desired solution

An annotation @PythonCall that is evaluated by the code generator that specifies how code should be rewritten. The annotation takes a string that can have placeholder that point either to this or a parameter. Example:

class List {
    @PythonCall("$delimiter.join($this)")
    fun join(delimiter: String) -> String
}

The code generator can then replace the placeholders with the actual values of this and the parameters. For the call [1, 2].join(', '), it would then generate the Python code ', '.join([1, 2]).

Possible alternatives (optional)

No response

Screenshots (optional)

No response

Additional Context (optional)

No response

Metadata

Metadata

Assignees

Labels

releasedIncluded in a release

Type

No type

Projects

Status

✔️ Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions