a way to refer to result type of an overloaded function
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 25/100
Hướng nghiên cứu
Bắt đầu với các ví dụ về hàm overloaded trong issue này và xem lại các cuộc thảo luận liên quan trong các issue #623 và #548. Không có tệp nào trong repository hoặc test nào được xác định; công việc chỉ được xem là hoàn tất khi có một phạm vi đã được thống nhất và có thể triển khai cho việc tham chiếu đến kiểu kết quả của một hàm overloaded.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
I am looking for a way to refer to result type of an overloaded function.
To illustrate:
import typing as tp
T = tp.TypeVar("T")
@tp.overload
def gf1(i: int, j: tp.Any) -> str:
...
@tp.overload
def gf1(i: tp.Iterable[T], j: bool) -> tp.Dict[T, T]:
...
def gf1(i: tp.Union[int, tp.Iterable[T]], j: tp.Any) -> tp.Union[str, tp.Dict[T, T]]:
pass
gf1.resultType = lambda *a: None
class C(tp.Generic[T]):
def f1(self) -> gf1.resultType(T, bool):
pass
def f2(self) -> gf1.resultType(tp.List[T], bool):
pass
if not tp.TYPE_CHECKING:
def reveal_type(x):
pass
# outputs: builtins.str
reveal_type(gf1(1, True))
# wanted: builtins.str
reveal_type(C[int]().f1())
# outputs: builtins.dict[builtins.int*, builtins.int*]
reveal_type(gf1([1], True))
# wanted: builtins.dict[builtins.int*, builtins.int*]
reveal_type(C[int]().f2())
The f.resultOf syntax is, of course, tentative.
Issue #623 seems to suggest that this may be achievable with a clever use of of Protocol but I just cannot twist my head around that.
Upon request I can elaborate on my specific use case for this but I believe it would suffice to say that in real code gf1.resultType would be used multiple times. Specific argument types for gf1 were chosen arbitrarily for the sake of example.
Not sure whether #548 is anyhow related.
- Ngôn ngữ chính
- Python
- Star
- 1.8k
- Fork
- 302
- Merge trung bình
- 23 giờ
- Pull request đã merge (30 ngày)
- 8
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
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/typing
-
topic: typing spec
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
-
topic: typing spec
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
-
topic: documentation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
-
topic: documentation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
-
topic: conformance tests topic: typing spec
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 72/100
Tất cả issue của python/typing
Issue tương tự
-
sponsored
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
-
opensubtitlescom: moviehash never sent when opensubtitles (.org) is not in the provider list Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
Diaoul/subliminal#1382 ·
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 92/100
-
triage/confirmed
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
agentscope-ai/agentscope#2775 ·
-
worker.gpuVendors silently accepts unsupported/misspelled vendor names — no validation guard Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100