Hacktoberfest 2026: die Issues, die Maintainer für den Oktober markiert haben – offen und einsteigerfreundlich. Hacktoberfest-Issues durchsuchen

Type error on server-side unary-unary handler code

Offen
#561 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Anfängerfreundlichkeit
45/100
Issue-Typ
Bug
Klarheit
Größtenteils klar
Aktivitätsstatus
Veraltet
Tech-Stack
grpc, python

Rechercherichtung

Beginne mit reproduce.proto und der generierten reproduce/init.py und konzentriere dich auf XBase.__rpc_y und den Aufruf von self.y. Führe protoc mit dem gezeigten Befehl erneut aus und führe anschließend mypy reproduce/init.py aus, um den Fehler zu reproduzieren. Erledigt ist die Aufgabe, wenn der generierte Handler mypy ohne den Fehler aufgrund des inkompatiblen Optional[Z]-Arguments besteht.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

bug investigation needed
Summary

Incompatible type error on generated unary-unary handler code.

Reproduction Steps

Write reproduce.proto:

syntax = "proto3";
package reproduce;

service X {
  rpc Y(Z) returns (Z) {}
}

message Z {}

Generate code with betterproto==2.0.0b6:

$ protoc -I . --python_betterproto_out=. reproduce.proto

Verify type error by mypy==1.8.0:

$ mypy reproduce/__init__.py
Expected Results

No mypy error

Actual Results
reproduce/__init__.py:55: error: Argument 1 to "y" of "XBase" has incompatible type "Z | None"; expected "Z"  [arg-type]
Found 1 error in 1 file (checked 1 source file)

Here's a chunk of the generated code which has the type error:

class XBase(ServiceBase):
    async def __rpc_y(self, stream: "grpclib.server.Stream[Z, Z]") -> None:
        request = await stream.recv_message()
        response = await self.y(request)
        #                       ^^^^^^^ Argument 1 to "y" of "XBase" has incompatible type "Z | None"; expected "Z"  [arg-type]
        await stream.send_message(response)

stream.recv_message() returns Optional[Z] so request might be None when the connection closes. But self.y() doesn't accept None because it's parameter type is Z but not Optional[Z].

System Information
libprotoc 25.3
Python 3.11.6
Name: betterproto
Version: 2.0.0b6
Summary: A better Protobuf / gRPC generator & library
Home-page: https://github.com/danielgtaylor/python-betterproto
Author: Daniel G. Taylor
Author-email: [email protected]
License: MIT
Location: .../.venv/lib/python3.11/site-packages
Requires: grpclib, python-dateutil
Required-by:
Name: grpclib
Version: 0.4.7
Summary: Pure-Python gRPC implementation for asyncio
Home-page: https://github.com/vmagamedov/grpclib
Author: Vladimir Magamedov
Author-email: [email protected]
License: BSD-3-Clause
Location: .../.venv/lib/python3.11/site-packages
Requires: h2, multidict
Required-by: betterproto
Name: mypy
Version: 1.8.0
Summary: Optional static typing for Python
Home-page: https://www.mypy-lang.org/
Author: Jukka Lehtosalo
Author-email: [email protected]
License: MIT
Location: .../.venv/lib/python3.11/site-packages
Requires: mypy-extensions, typing-extensions
Required-by:
Checklist
  • I have searched the issues for duplicates.
  • I have shown the entire traceback, if possible.
  • I have verified this issue occurs on the latest prelease of betterproto which can be installed using pip install -U --pre betterproto, if possible.
Vorherrschende Sprache
Python
Sterne
1.8k
Forks
235
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus danielgtaylor/python-betterproto

Alle Issues in danielgtaylor/python-betterproto

Ähnliche Issues

Weitere Issues zu Python

Neue Issues direkt in Ihr Postfach

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