@@ -458,9 +458,9 @@ export class PyObject {
458458 const view = new DataView ( pyMethodDef . buffer ) ;
459459 const LE =
460460 new Uint8Array ( new Uint32Array ( [ 0x12345678 ] ) . buffer ) [ 0 ] !== 0x7 ;
461- const nameBuf = new TextEncoder ( ) . encode (
462- "JSCallback:" + ( v . callback . name || "anonymous" ) + "\0" ,
463- ) ;
461+
462+ const name = "JSCallback:" + ( v . callback . name || "anonymous" ) ;
463+ const nameBuf = new TextEncoder ( ) . encode ( ` ${ name } \0` ) ;
464464 view . setBigUint64 (
465465 0 ,
466466 BigInt ( Deno . UnsafePointer . value ( Deno . UnsafePointer . of ( nameBuf ) ! ) ) ,
@@ -472,9 +472,19 @@ export class PyObject {
472472 LE ,
473473 ) ;
474474 view . setInt32 ( 16 , 0x1 | 0x2 , LE ) ;
475+ // https://github.com/python/cpython/blob/f27593a87c344f3774ca73644a11cbd5614007ef/Objects/typeobject.c#L688
476+ const SIGNATURE_END_MARKER = ")\n--\n\n" ;
477+ // We're not using the correct arguments name, but just using dummy ones (because they're not accessible in js)
478+ const fnArgs = [ ...Array ( v . callback . length ) . keys ( ) ]
479+ . map ( ( _ , i ) => String . fromCharCode ( 97 + i ) ) . join ( "," ) ;
480+ const docBuf = `${ name } (${ fnArgs } ${ SIGNATURE_END_MARKER } \0` ;
475481 view . setBigUint64 (
476482 24 ,
477- BigInt ( Deno . UnsafePointer . value ( Deno . UnsafePointer . of ( nameBuf ) ! ) ) ,
483+ BigInt (
484+ Deno . UnsafePointer . value (
485+ Deno . UnsafePointer . of ( new TextEncoder ( ) . encode ( docBuf ) ) ! ,
486+ ) ,
487+ ) ,
478488 LE ,
479489 ) ;
480490 const fn = py . PyCFunction_NewEx (
0 commit comments