Skip to content

Binder: a KSP function returning a Kotlin class gives a generic _PmObject, not the rendered class proxy #94

Closed

Description

@b-re-w

What

A KSP-scanned top-level function returning a Kotlin class reaches Python as a generic _PmObject, not as the rendered class proxy. The class's methods and properties can't be reached from Python. The result is owned, so no handle leaks, but it is untyped.

Evidence (found by the TypedPython #45 test, interpreted and compiled paths alike)

fun tpSample(index: Long, weight: Double): TpSample in ksp-fixtures/app returned <class '__main__._PmObject'> from tpSample(3, 0.5), so isinstance(_, TpSample) was False and '_PmObject' object has no attribute 'weigh' was raised. A TpSample(...) built with the constructor is a proper proxy.

Code path

  • PythonProxySource.renderOne, the non-suspend body (~line 946), returns owned(entry, "_pm_invoke(...)"). owned() emits _pm_own(result, '<returnTypeName>') whenever ownedTypeOf(entry) is non-null.
  • _pm_own (in OWNED_HANDLE, ~line 759) always returns _PmObject(_pm_h, _pm_t). It never looks up the class rendered for _pm_t.
  • Methods (~1264/1275) and static functions (~1304/1315) use the same owned(), so they likely behave the same way. Not observed.

Docs that disagree with the code

  • python-multiplatform-ksp/.../FragmentScanner.kt:198 (topLevelFunctionEntry) sets returnTypeName, and Model.kt:53 documents it as filled.
  • PythonProxySource.kt:925 (the ownedTypeOf KDoc) still says KSP supplies none.
  • Lines 255–256 ("What is still not rendered") say "KSP emits no return type name". They also say wrapping in the rendered class would gain nothing because no rendered class shares a name with a returned type. That no longer holds for KSP.

Done when

A KSP function returning a bound Kotlin class returns an instance of that class's rendered proxy (methods and properties work), with ownership unchanged. A ksp-fixtures test covers a top-level function return and a method return.

Activity

  1. added a commit that references this issue on Oct 3, 2026
  2. b-re-w commented on Oct 3, 2026

    @b-re-w
    MemberAuthor

    Landed in develop via #111.

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions