mypy plugin allows false positive error when exhaustively pattern matching on Result
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 48/100
Hướng nghiên cứu
Tái hiện báo cáo bằng ví dụ pattern_div.py được示 và cấu hình mypy trong pyproject.toml. Sau đó kiểm tra entry point returns.contrib.mypy.returns_plugin và các bài kiểm thử plugin hiện có, nếu có. Hoàn thành khi việc đối sánh đầy đủ Success/Failure không còn tạo ra lỗi missing-return và có một bài kiểm thử hồi quy bao quát ví dụ này.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Bug report
What's wrong
Again, this is a really cool project ❤️
Consider the following code:
from enum import Enum, auto
import math
from typing import TypeAlias
from returns.result import Failure, Result, Success
class MathError(Enum):
DivisionByZero = auto()
NonPositiveLogarithm = auto()
MathResult: TypeAlias = Result[float, MathError]
def div(x: float, y: float) -> MathResult:
if y == 0.0:
return Failure(MathError.DivisionByZero)
return Success(x / y)
def ln(x: float) -> MathResult:
if x <= 0.0:
return Failure(MathError.NonPositiveLogarithm)
return Success(math.log(x))
def op_(x: float, y: float) -> MathResult:
z = div(x, y)
match z:
case Success(ratio):
return ln(ratio)
case Failure(_):
return z
mypy configuration in pyproject.toml
[tool.mypy]
ignore_missing_imports = true
strict = true
plugins = [
"returns.contrib.mypy.returns_plugin",
]
Running:
$ mypy pattern_div.py
pattern_div.py:32: error: Missing return statement
Related to #1090
How is that should be
As far as I can tell (new to returns), I'm matching exhaustively here, so I would not expect a mypy error.
mypy seems to understand exhaustive matching in general. mypy does not throw a type checking error in the following snippet.
def test(err: MathError) -> int:
match err:
case MathError.DivisionByZero:
return 0
case MathError.NonPositiveLogarithm:
return 1
System information
pythonversion: 3.10.2returnsversion: 0.19.0mypyversion: 0.942
$ pip list
Package Version
----------------- -------
black 22.3.0
click 8.1.2
distlib 0.3.4
filelock 3.6.0
isort 5.10.1
mypy 0.942
mypy-extensions 0.4.3
packaging 21.3
pathspec 0.9.0
pep517 0.12.0
pip 22.0.4
pip-tools 6.6.0
platformdirs 2.5.1
pluggy 1.0.0
py 1.11.0
pyparsing 3.0.8
returns 0.19.0
setuptools 62.1.0
six 1.16.0
toml 0.10.2
tomli 2.0.1
tox 3.25.0
typing_extensions 4.1.1
virtualenv 20.14.1
wheel 0.37.1
- Ngôn ngữ chính
- Python
- Star
- 4.4k
- Fork
- 154
- Merge trung bình
- 3 giờ 5 phút
- Pull request đã merge (30 ngày)
- 22
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của dry-python/returns
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
dry-python/returns#2394 · 1 reaction ·
-
Composing 0-argument functions Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 52/100
dry-python/returns#2365 ·
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
dry-python/returns#2355 · 1 bình luận ·
-
bug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 45/100
dry-python/returns#2295 · 4 bình luận · 1 reaction ·
-
bug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 45/100
dry-python/returns#2253 · 2 bình luận ·
Tất cả issue của dry-python/returns
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
browser-use/browser-use#5905 ·
-
type: enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
ynput/ayon-python-api#363 ·
-
bug needs triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
modelscope/FunASR#3728 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
open-compass/opencompass#2655 ·