danielgtaylor / danielgtaylor/python-betterproto

Documentation errors

Offen
#208 1 Kommentar 3 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
documentation
Vorherrschende Sprache
Python
Sterne
1.8k
Forks
234
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

There're a few issues with the example server, even after using the prerelease version. Probably not worth a PR, so here's an update example with notes below:

```python
import asyncio

from echo import EchoBase, EchoResponse, EchoStreamResponse
from grpclib.server import Server
from typing import AsyncIterator

class EchoService(EchoBase):
async def echo(self, value: str, extra_times: int) -> EchoResponse:
return EchoResponse(values=[value] * extra_times)

async def echo_stream(
self, value: str, extra_times: int
) -> AsyncIterator[EchoStreamResponse]:
for _ in range(extra_times):
yield EchoStreamResponse(value=value)

async def start_server():
HOST = "127.0.0.1"
PORT = 50051
server = Server([EchoService()])
await server.start(HOST, PORT)
await server.wait_closed()

if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.run_until_complete(start_server())
loop.close()

```

### Changes

- Added imports of `EchoReponse` and `EchoStreamResponse`
- Updated `echo` and `echo_stream` to return the correct types
- Updated `PORT` to match that in the client example
- Replaced `await server.run_forever()` (raises a `NotImplementedError`) with `await server.wait_closed()`
- Added an asyncio loop at the bottom to actually run the server

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Start with the example server documentation and compare its code with the client example. Update the imports, response types, port, server shutdown call, and asyncio entry point as listed; done means the example matches the working server behavior and can be run without the reported errors.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
grpc, python
Bereich
documentation
Issue-Typ
Dokumentation
Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
25/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.