Prevent an implementation for `int` class from operating on `bool` values
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 45/100
Hướng nghiên cứu
Bắt đầu bằng cách tái hiện ví dụ với classes 0.4.0, sau đó lần theo dispatch từ khai báo typeclass và đăng ký render.instance(int). Công việc được xem là hoàn tất khi render(True) không còn sử dụng triển khai int mà thay vào đó phát sinh NotImplementedError cho trường hợp bool chưa được chỉ định.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Context. Consider the following piece of code.
from classes import typeclass
@typeclass
def render(data_value) -> str:
"""Pretty-print a value."""
@render.instance(int)
def _render_int(data_value: int) -> str:
return f'🔢 {data_value}'
render(True) == '🔢 True'
(this should be runnable as-is on classes 0.4.0.)
I would have expected this code to fail with a NotImplementedError because the bool case wasn't specified; but instead, that case is handled by the int implementation because
In [3]: issubclass(bool, int)
Out[3]: True
Decision. In an int implementation, recognize if the provided value is actually a bool and refuse to process that value.
Consequences. I have been writing in Python for quite a few years now and I might even have encountered this relationship between int and bool types before, but that is not quite a type of thing that I keep in my short-term memory to be able to instantly recognize.
I believe this change can help avert bugs which might be hard to trace otherwise.
- Ngôn ngữ chính
- Python
- Star
- 730
- Fork
- 30
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
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 dry-python/classes
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
dry-python/classes#496 ·
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 45/100
dry-python/classes#494 ·
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 52/100
dry-python/classes#492 · 2 bình luận ·
-
bug
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
dry-python/classes#481 · 5 bình luận · 4 reaction ·
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 35/100
dry-python/classes#386 ·
Tất cả issue của dry-python/classes
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 ·