Idea: add Char type to represent Text with size = 1
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
Issue không nêu tên tệp, test hay entry point nào; hãy bắt đầu bằng việc xem xét semantics được đề xuất cho Char và Text trong issue. Công việc được xem là hoàn tất khi có một design được thống nhất, bao quát behavior khi iterable, indexing và slicing, compatibility, cùng các quy tắc nối chuỗi.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Due to the lack of character type in Python, a function that accept List[Text] will need to be extra careful when generalize the accepted argument type. Iterable[Text] and Sequence[Text] clearly doesn't work:
In [1]: import collections.abc
In [2]: isinstance("foo", collections.abc.Sequence)
Out[2]: True
In [3]: isinstance("foo", collections.abc.Iterable)
Out[3]: True
The closest thing you can do is to do something like Union[List[Text], Set[Text], Tuple[Text]] but it will not work with things like KeysView.
How about having a typing.Char to represent Text with length=1, and dedicate Text to a type with at least 2 characters?
Some examples to illustrate the usage:
def foo(xs: Iterable[Text]):
return '|'.join(xs)
# list(Text) should return List[Char]
foo("abcd") # error
foo(list("abcd")) # correct, List[Char] is a special case of List[Text]
def bar(xs: Iterable[Char]):
return '|'.join(xs)
bar("abcd") # correct, Text is a Iterable[Char]
bar(list("abcd")) # correct, List[Char] is a Iterable[Char]
bar(["ab", "cd"]) # error, List[Text] is not a Iterable[Char]
a: Char = 'a'
a[1] # error, Char cannot be indexed beyond index 0
a[0] # should be an error from type checking's PoV, Char should never be indexed
a[:] # should be an error from type checking's PoV, Char should never be copied as a slice
b: Text = 'b'
a + b # should be an error from type checking's PoV, Char and Text should be considered incompatible types
typing.cast(Text, a) + b # correct
c = a + a # correct, concatenate Char gets Text (but I'm not sure if this is reasonable though, what if we do (a + a) + a ?)
- 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 82/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
use-agent-os/agent-os#3314 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
BasedHardware/omi#15662 · 1 bình luận ·
-
documentation help wanted
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 90/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
AiursoftWeb/AnduinOS-2#19 ·