Can't use a subscripted `ThingSlot`

Đang mở
#417 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 3 ngày

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
55/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
fastapi, python
Lĩnh vực
backend

Hướng nghiên cứu

Start by reading the ThingSlot and BaseDescriptor definitions and the code that handles __orig_class__; the issue identifies the mismatch between the one-parameter subscription and the descriptor’s two type parameters. Check existing tests for thing_slot() and descriptor typing behavior. Done means ThingSlot[MyOtherThing]() works as expected or the supported behavior is documented clearly.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Describe the bug
The public API says I should define a Thing Slot like:

class MyThing(lt.Thing):
    other_thing: MyOtherThing = lt.thing_slot()

This works fine.

I expected I could also do this:

class MyThing(lt.Thing):
    other_thing = ThingSlot[MyOtherThing]()

The second form (which isn't recommended anywhere) does not work. The reason for this is that BaseDescriptor expects two type parameters, the first is the host class and the second is the value. When it calls __orig_class__, it gets ThingSlot[ValueType] and not BaseDescriptor[lt.Thing, ValueType].

To Reproduce
Define a ThingSlot using the type in a subscript, as shown above.

Expected behaviour
I hoped the two examples above would be equivalent.

Additional context
The subscripted form is not really used or recommended anywhere. We could just remove it - but I feel like it has its uses. This isn't blocking anything, so it's likely to sit in the backlog for a little while.

Ngôn ngữ chính
Python
Star
10
Fork
4
Merge trung bình
4 ngày 15 giờ
Pull request đã merge (30 ngày)
11

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của labthings/labthings-fastapi

Tất cả issue của labthings/labthings-fastapi

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.