SupportsRound[int] hinted functions work with floats if round is called with no additional args
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
- 35/100
Hướng nghiên cứu
Tái hiện ví dụ scratch.py được cung cấp bằng mypy 0.761 hoặc master, sau đó kiểm tra định nghĩa round được liên kết trong typeshed stdlib/2and3/builtins.pyi. Xác định xem điểm không khớp thuộc về mypy hay typeshed, và so sánh hành vi với các issue liên quan. Hoàn tất có nghĩa là đã xác nhận bên chịu trách nhiệm và lời gọi round() được mong đợi đã được bao phủ bởi một kiểm thử phù hợp hoặc được chuyển giao.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Note: if you are reporting a wrong signature of a function or a class in
the standard library, then the typeshed tracker is better suited
for this report: https://github.com/python/typeshed/issues
this genuinely might be a typeshed issue i'm not 100% sure. To be sure some similar issues about __round__ have cropped up both here and in typeshed:
#6211
python/typeshed#2638
If maintainers think this is solely a typeshed issue and would like me to repost over there please just let me know. If it is a typeshed issue and is a regression ( which it may be) then perhaps I could help by adding a test somewhere?
Are you reporting a bug, or opening a feature request?
possible bug
Example:
import typing
def round_it(x: typing.SupportsRound[int]) -> int:
return round(x)
round_it(3.2)
What is the actual behavior/output?
though round is called with no ndigits arg in the example above we still get the following error when running mypy:
scratch.py:11: error: Argument 1 to "round_it" has incompatible type "float"; expected "SupportsRound[int]"
scratch.py:11: note: Following member(s) of "float" have conflicts:
scratch.py:11: note: Expected:
scratch.py:11: note: @overload
scratch.py:11: note: def __round__(self) -> int
scratch.py:11: note: @overload
scratch.py:11: note: def __round__(self, ndigits: int) -> int
scratch.py:11: note: Got:
scratch.py:11: note: @overload
scratch.py:11: note: def __round__(self, ndigits: None = ...) -> int
scratch.py:11: note: @overload
scratch.py:11: note: def __round__(self, ndigits: int) -> float
note that even if I modify this bit of typeshed to include :
@overload
def __round__(self, ndigits: None = ...) -> int: ...
I still have the same issue ( just with <1 more overload not shown>, etc)
What is the behavior/output you expect?
since SupportsRound is parameterised by return type and I have called the round method with no extra args I would expect that the example provided above would pass.
Specifically :
given both float and SupportsRound[int] more or less share a signature for the def __round__(self) and round is called w/ no args. I would expect mypy to be able to interpret that we're using def __round__(self, ndigits: None = ...) -> int and not care about the conflicting overload since it's not called.
What are the versions of mypy and Python you are using?
python: 3.8.0
mypy: 0.761 (and master)
What are the mypy flags you are using?
I have tried running with each of the following flag sets :
- no flags
--strict--no-implicit-optional--no-strict-optional--strict-optional
- Ngôn ngữ chính
- Python
- Star
- 20.6k
- Fork
- 3.3k
- Merge trung bình
- 1 ngày 18 giờ
- Pull request đã merge (30 ngày)
- 54
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 python/mypy
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
-
documentation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
-
bug topic-configuration topic-error-reporting
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
bancolombia/sentinel#23 ·
-
test md Đang mởCI
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
langchain-ai/deepagents#6450 ·
-
bug client
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100