Mypy type checking does not work with enums
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 35/100
Direzione di ricerca
Inizia eseguendo mypy sulla riproduzione test-mypy.py fornita con la versione interessata di betterproto, quindi esamina le modifiche al tipaggio degli enum associate a #293 e #540. Il lavoro è completato quando mypy tratta Colour.RED e Colour.try_value(Colour.RED) come valori Colour e l’esempio passa senza l’errore argument-type segnalato.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Summary
When using an enum in a code project mypy is broken and has the impression that all the enum fields are of type 'int'
Reproduction Steps
Run type checking on this file and see the problem in version 2.0.0b7
import betterproto
class Colour(betterproto.Enum):
RED = 1
GREEN = 2
BLUE = 3
def print_color(color: Colour) -> None:
print(color.value)
def test_mypy_types() -> None:
print(Colour.RED == Colour.try_value(Colour.RED))
print_color(Colour.RED)
print_color(Colour.try_value(Colour.RED))
if __name__ == '__main__':
test_mypy_types()
Expected Results
I would have expected the type checking to pass as in version 2.0.0-beta6
This is caused by #293 (and is not solved by #540)
The expected type of Colour.RED is a Colour not an int.
Actual Results
$ poetry run mypy test-mypy.py
test-mypy.py:16: error: Argument 1 to "print_color" has incompatible type "int"; expected "Colour" [arg-type]
print_color(Colour.RED)
^~~~~~~~~~
Found 1 error in 1 file (checked 1 source file)
System Information
Python 3.11.9
Name: betterproto
Version: 2.0.0b7
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: /home/jns/product/.venv/lib/python3.11/site-packages
Requires: grpclib, python-dateutil, typing-extensions
Required-by: inventory_code_project_enumeration, inventory_name_inference, inventory_py_schema_description, inventory_py_schema_endpoints_extraction, inventory_py_schema_services_extraction, inventory_repository_analysis, inventory_repository_clone, inventory_repository_extract_schema, inventory_repository_extract_secret, inventory_repository_extract_service, inventory_repository_owner_search, inventory_schema_analysis, inventory_schema_classification, inventory_schema_conversion, inventory_schema_data_leaks, inventory_service_description, inventory_software_types_fingerprinter, protocol
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
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
volcengine/OpenViking#6445 ·
I maintainer di solito rispondono entro 1 giorno
-
BUG:Edit Album strips spaces from the password so albums with a leading/trailing space in the password can't be editedForse già presa @ManyaJain111 l’ha presa oggi. Apertabug enhancement possible-duplicate
Difficoltà 2/5 1-3 ore Idoneità per principianti 77/100
AOSSIE-Org/PictoPy#1637 · 4 commenti ·
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
deepspeedai/DeepSpeed#8884 ·
I maintainer di solito rispondono entro 3 giorni
-
Flaky: test_advisor_live_calibrates_an_unmeasured_circuit ranks engines by a 1.8ms sleep marginAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
flagos-ai/FlagQuantum#718 ·
I maintainer di solito rispondono entro 1 giorno
-
bug CI-failure high priority
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 86/100
vllm-project/afd-plugin#483 ·
I maintainer di solito rispondono entro 1 giorno