Allow to use function objects as singletons
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
- 30/100
- Loại issue
- Tính năng
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- python
- Lĩnh vực
- developer-experience
Hướng nghiên cứu
Bắt đầu với ví dụ singleton bằng factory function và phần so sánh với các Enum singleton trong issue #668. Vì issue không nêu tên tệp triển khai hoặc test nào, trước tiên hãy xác định nơi typing biểu diễn các giá trị singleton và cách các đối tượng hàm hiện đang được xử lý. Được coi là hoàn thành khi xác định được liệu các đối tượng hàm này có thể được chấp nhận và biểu diễn riêng biệt trong type hint hay không, với coverage cho trường hợp kiểu Element/Comment.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
I was trying to create some stubs for lxml library, but I encountered a function that depending on a function object it gets (as in specific function object - checked with identity check) only finds objects of specific type.
Here's a very simplified mock-up of it so that you can get some idea on what I mean (the typing for arg argument in the find function is incorrect and that's what I want to be able to type hint in some way):
from typing import Union
class _Element: ...
def Element() -> _Element: ...
class _Comment: ...
def Comment() -> _Comment: ...
def find(arg: Union[Element, Comment]) -> Union[_Element, _Comment]:
if arg is Element:
# only find _Element objects
elif arg is Element:
# only find _Comment objects
# this function should only accept `Element` and `Comment` function object
find(arg=Element)
So basically those functions serve as a singletons. Unfortunately typing.Union only allows Enums to work as singletons.
I am not entirely sure if this should be supported, usually the code could just be adjusted to use Enums, but in this case it will be used for type stubs so the code can't be edited. And to be honest, I am not sure if the code really needs editing in that case as if I didn't need typing for that library, I would say it's actually quite intuitive to use these factory functions as arguments in this case.
- 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ự
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 90/100
learningequality/ricecooker#747 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
BSData/horus-heresy-3rd-edition#3171 ·
-
enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
run-llama/llama_index#23199 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
KhronosGroup/glTF-Blender-IO#2769 ·