Mypy type checking does not work with enums
还没有人认领这个 Issue。
评估
调研方向
首先,使用受影响的 betterproto 版本对提供的 test-mypy.py 复现代码运行 mypy,然后检查与 #293 和 #540 相关的枚举类型标注更改。当 mypy 将 Colour.RED 和 Colour.try_value(Colour.RED) 视为 Colour 值,并且示例在没有报告的 argument-type 错误的情况下通过时,即表示完成。
由索引模型根据 Issue 内容生成。
描述
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.
- 主要语言
- Python
- 星标
- 1.8k
- 派生
- 235
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
danielgtaylor/python-betterproto 的其他 Issue
-
难度 3/5 1-2 天 新手友好度 55/100
-
难度 5/5 一周以上 新手友好度 15/100
-
bug investigation needed
难度 3/5 1-2 天 新手友好度 42/100
-
bug investigation needed
难度 3/5 1-2 天 新手友好度 45/100
-
bug investigation needed
难度 4/5 3-5 天 新手友好度 38/100
danielgtaylor/python-betterproto#676 · 3 条评论 ·
查看 danielgtaylor/python-betterproto 的全部 Issue
相似的 Issue
-
[Bug]: Revit selector reads process ids 2000-2099 as years (flaky AgentClientTests.AYearOrAProcessIdSelectsTheHost)可能已有人在做 @Wurschdhaud 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 83/100
pyrevitlabs/pyRevit#3817 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 85/100
521xueweihan/HelloGitHub#4074 ·
-
follow-up
难度 2/5 1-3 小时 新手友好度 62/100
维护者通常 1 天内回复
-
Helm chart: allow setting ingressClassName on the Ingress可能已有人在做 @commarla 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 85/100
pgadmin-org/pgadmin4#10658 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100