Type error on server-side unary-unary handler code
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 45/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Ferma
- Stack tecnologico
- grpc, python
- Ambito
- backend-api-design, devtools
Direzione di ricerca
Inizia da reproduce.proto e dal reproduce/init.py generato, concentrandoti su XBase.__rpc_y e sulla chiamata a self.y. Esegui nuovamente protoc con il comando mostrato, quindi esegui mypy reproduce/init.py per riprodurre l'errore. È completato quando l'handler generato supera mypy senza l'errore relativo all'argomento Optional[Z] incompatibile.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- Python
- Stelle
- 1.8k
- Fork
- 235
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di danielgtaylor/python-betterproto
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 55/100
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 15/100
-
bug investigation needed
Difficoltà 3/5 1-2 giorni Idoneità per principianti 42/100
-
bug investigation needed
Difficoltà 3/5 1-2 giorni Idoneità per principianti 45/100
-
bug investigation needed
Difficoltà 4/5 3-5 giorni Idoneità per principianti 38/100
danielgtaylor/python-betterproto#676 · 3 commenti ·
Tutte le issue di danielgtaylor/python-betterproto
Issue simili
-
follow-up
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
I maintainer di solito rispondono entro 1 giorno
-
Download helper still uses huggingface_hub arguments removed in 1.0: USE_SYMLINKS is silently ignored and every download ends with a WinError 3 lineForse già presa @li-lizhe l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
-
IPv6 node addresses produce an invalid request URLForse già presa @RaphaelFakhri l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
typesense/typesense-python#154 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
elastic/elasticsearch-py#3592 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 77/100
developmentseed/titiler-cmr#250 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno