Python async interface bridge ignores untyped parameters
Expected behavior
An untyped optional Python parameter should not prevent an async def from implementing a Java interface method whose return type is Publisher, Mono, or Flux.
This is the behavior documented in Async/Await: the coroutine should be adapted to the declared reactive return type and start on subscription.
Reproducer
Add a Java interface method:
default Mono<String> findWithCallback(String id, Consumer<String> callback) {
return Mono.just("default");
}and override it in Python:
async def findWithCallback(self, id: str, callback=None) -> str:
return idCalling finder.findWithCallback("c", null).block() fails. A focused regression test reproduces this in ReactiveReturnTypeSpec on the 5.2.x branch.
Actual behavior
The generated Java class contains two methods:
- The interface-compatible
Publisher/Monomethod treats the coroutine itself as aPublisherand callsconvertPublisher. - A second
CompletionStageoverload is generated from the Python method.
Subscription then fails with:
UnsupportedOperationException: Unsupported operation identifier 'subscribe' and object '<coroutine object ...>'Root cause
PythonStubGenerator.resolveDeclaredBridgeMethod does not select the Python method when an untyped parameter resolves to Object but the corresponding Java parameter is more specific, such as Consumer. Async detection therefore sees the Java interface method instead of the Python async def, bypassing the existing coroutine-to-Publisher path.
Parameter names do not affect this. Requiring a java.util.function.Consumer annotation would expose Java implementation details in otherwise idiomatic Python code.
Versions
- Micronaut Core
5.2.xatb3464ec - GraalPy
25.4.4.1.1 - Also reproduced end-to-end with Pyronaut
0.0.4and Micronaut Core5.2.5
Source: micronaut-projects/micronaut-core