Mypy type checking does not work with enums
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Accessibilité débutants
- 35/100
Piste de recherche
Commencez par exécuter mypy sur la reproduction test-mypy.py fournie avec la version concernée de betterproto, puis examinez les modifications du typage des enum associées à #293 et #540. C’est terminé lorsque mypy traite Colour.RED et Colour.try_value(Colour.RED) comme des valeurs Colour et que l’exemple réussit sans l’erreur argument-type signalée.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
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.
- Langage dominant
- Python
- Étoiles
- 1.8k
- Forks
- 235
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Préparer son environnement
- Aucun Dockerfile ni fichier Docker Compose
- Propose un modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de danielgtaylor/python-betterproto
-
Difficulté 3/5 1-2 jours Accessibilité débutants 55/100
-
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 15/100
-
bug investigation needed
Difficulté 3/5 1-2 jours Accessibilité débutants 42/100
-
bug investigation needed
Difficulté 3/5 1-2 jours Accessibilité débutants 45/100
-
bug investigation needed
Difficulté 4/5 3-5 jours Accessibilité débutants 38/100
danielgtaylor/python-betterproto#676 · 3 commentaires ·
Toutes les issues de danielgtaylor/python-betterproto
Issues similaires
-
[oblt-aw][autodoc] Update workflow docs for gh-aw v0.92.5 and detector permission scopePeut-être pris @github-actions l’a pris aujourd’hui. Ouverte
Difficulté 1/5 1-3 heures Accessibilité débutants 88/100
Les mainteneurs répondent en général sous 1 jour
-
enhancement
Difficulté 2/5 1-3 heures Accessibilité débutants 82/100
Les mainteneurs répondent en général sous 1 jour
-
feat(ide): VS Code access through the shipped MCP server (config doc and tool-list smoke test)Ouverteroadmap-100
Difficulté 2/5 1-3 heures Accessibilité débutants 82/100
Les mainteneurs répondent en général sous 1 jour
-
comp/tools P2 tool/browser tool/file type/bug
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
NousResearch/hermes-agent#143418 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
python-hyper/uritemplate#164 ·