{"record":{"id":"840618427c41addc","repo":"python/cpython","slug":"not-implemented","errorCode":null,"errorMessage":"Not implemented","messagePattern":"Not implemented","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"Platforms/emscripten/web_example_pyrepl_jspi/src.mjs","lineNumber":132,"sourceCode":"    return await Promise.race([p1, p2, p3]);\n  } finally {\n    h1.dispose();\n    h2.dispose();\n    h3.dispose();\n  }\n}\n\nconst FIONREAD = 0x541b;\n\nconst tty_stream_ops = {\n  async readAsync(stream, buffer, offset, length, pos /* ignored */) {\n    let readBytes = PTY.read(length);\n    if (length && !readBytes.length) {\n      const status = await waitForReadable(-1);\n      if (status === waitResult.READY) {\n        readBytes = PTY.read(length);\n      } else {\n        throw new Error(\"Not implemented\");\n      }\n    }\n    buffer.set(readBytes, offset);\n    return readBytes.length;\n  },\n\n  write: (stream, buffer, offset, length) => {\n    // Note: default `buffer` is for some reason `HEAP8` (signed), while we want unsigned `HEAPU8`.\n    buffer = new Uint8Array(\n      buffer.buffer,\n      buffer.byteOffset,\n      buffer.byteLength,\n    );\n    const toWrite = Array.from(buffer.subarray(offset, offset + length));\n    PTY.write(toWrite);\n    return length;\n  },\n","sourceCodeStart":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/python/cpython/blob/bc6749cc3b5ae4a5e88a6cc2d5b3bebbe354eae6/Platforms/emscripten/web_example_pyrepl_jspi/src.mjs#L114-L150","documentation":"Raised by _ProactorBaseWritePipeTransport.sendto() (the proactor datagram transport, Windows IOCP) when the data argument is not a bytes-like object. Only bytes, bytearray, and memoryview are accepted; anything else (str, None, int, arbitrary objects) fails this isinstance check. The message text uses old %-style formatting, so it appears with a literal %r placeholder in some versions.","triggerScenarios":"Calling transport.sendto(data) or loop.sock_sendto-related datagram sends where data is a str (e.g. forgot .encode()), None from a failed serialization, a dict/list payload not json.dumps'd, or a generator. Also triggered when sendto is used on a connected TCP-style transport's API by mistake.","commonSituations":"Encoding mistakes: passing 'hello' instead of b'hello'; JSON over UDP where json.dumps(...) (str) is sent without .encode('utf-8'); a producer function returning None on an error path that gets sent anyway; pandas/numpy objects assumed to be buffers.","solutions":["Encode string payloads before sending: data.encode('utf-8') for str, json.dumps(obj).encode() for objects","Fix upstream functions that return None or non-bytes on error instead of sending their result","Pass bytes(bytearray/memoryview) directly; convert numpy arrays with .tobytes() if needed","Add a unit test asserting the payload type before send"],"exampleFix":"# before\ntransport.sendto(json.dumps({'cmd': 'ping'}))  # str -> TypeError\n# after\ntransport.sendto(json.dumps({'cmd': 'ping'}).encode('utf-8'))","handlingStrategy":"type-guard","validationCode":"def to_wire(data):\n    if isinstance(data, str):\n        return data.encode('utf-8')\n    if isinstance(data, (bytes, bytearray, memoryview)):\n        return data\n    raise TypeError(f'cannot send {type(data).__name__} over datagram')","typeGuard":"def is_wire_bytes(d) -> bool:\n    return isinstance(d, (bytes, bytearray, memoryview))","tryCatchPattern":"try:\n    tr.sendto(payload)\nexcept TypeError as e:\n    if 'bytes-like' in str(e):\n        raise TypeError(f'encode {type(payload).__name__} before send') from e\n    raise","preventionTips":["Encode at the boundary: json.dumps(...).encode('utf-8')","Never send the result of functions that can return None on failure","Add type annotations (bytes) on send helpers so mypy catches str payloads","Unit-test the serializer output type"],"tags":["asyncio","udp","typeerror","encoding","windows"],"backgroundTag":null,"analyzedSha":"bc6749cc3b5ae4a5e88a6cc2d5b3bebbe354eae6","analyzedAt":"2026-08-14T22:01:13.976Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}