Properties `.start`, `.stop`, `. step` of (generic) `slice[...]` should be optional (`| None`)
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 55/100
Hướng nghiên cứu
Bắt đầu từ slice stub tổng quát của typeshed và xem xét các annotation new được thảo luận trong #13008 cùng với phương án thay thế trong #13007. Kiểm tra các ví dụ slice(42) của issue với các kiểu của .start, .stop và .step; hoàn tất khi các annotation vẫn giữ None và hành vi type-checking được nêu là chính xác.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Situation
#13008 made slice.__new__ more precise. Generic slice[T] accepts T | None as arguments when creating a slice.
However, properties .start, .stop, . step of (generic) slice[...] are typed as there respective types, i.e. T in above example.
Consequence
This leads to typecheckers accepting:
def test(s: slice[int]) -> None:
assert_type(s.start, int)
if s.start is None:
assert_never(s.start)
whereas below obviously breaks:
test(slice(42))
Solution
Therefore, I suggest properties .start, .stop, . step should have optional (| None) return types:
@property
def start(self) -> _StartT_co | None: ...
@property
def step(self) -> _StepT_co | None: ...
@property
def stop(self) -> _StopT_co | None: ...
Alternative
Currently, typeshed uses slice[...] as slice[T | None] explicitly as per #13007, e.g.
class str:
def __getitem__(self, key: SupportsIndex | slice[SupportsIndex | None], /) -> str: ...
While that works/typechecks correctly:
def test(s: slice[int | None]) -> None:
assert_type(s.start, int | None)
if s.start is None or isinstance(s.start, int):
pass
else:
assert_never(s.start)
test(slice(42)) # okay
test(slice('x')) # error: Argument 1 to "slice" has incompatible type "str"; expected "int | None" [arg-type]
I see as downsides:
- it's error-prone / less ergonomic
- it renders part of #13008
__new__overloading complexity superfluous - it made #13007 more complex
Question
@Sachaa-Thanasius: Was the proposed solution considered for #13007?
- Ngôn ngữ chính
- Python
- Star
- 5.1k
- Fork
- 2.1k
- Merge trung bình
- 2 ngày 7 phút
- Pull request đã merge (30 ngày)
- 116
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc 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/typeshed
-
`networkx.set_edge_attributes` should support scalar value + nameCó thể đã có người làm @Fire162 đã nhận 9 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 67/100
Maintainer thường phản hồi trong vòng 1 ngày
-
false alarm on decode callCó thể đã có người làm @jw9829 đã nhận 36 ngày trước. Đang mởhelp wanted stubs: false positive
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
python/typeshed#16441 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Don't run pyright basic checks on projects with strict pyright settings in CICó thể đã có người làm @Mohith1612 đã nhận 73 ngày trước. Đang mởproject: infrastructure
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
python/typeshed#16005 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
stubs: improvement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
python/typeshed#15548 · 5 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
stubs: improvement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 64/100
python/typeshed#15529 · 5 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của python/typeshed
Issue tương tự
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
aws/sagemaker-python-sdk#6554 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 78/100
huggingface/diffusers#15170 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[BUG] LLM conflict check ignores MNEMOSYNE_LLM_MAX_TOKENS, so reasoning models return empty repliesĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
mnemosyne-oss/mnemosyne#1325 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement meshtastic-2.8
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
pskillen/meshflow-api#459 ·