Can't use a subscripted `ThingSlot`

Open
#417 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 3 days

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
55/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
fastapi, python
Domain
backend

Research direction

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.

Written by the indexing model from the issue text.

Description

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.

Dominant language
Python
Stars
10
Forks
4
Avg merge
4d 15h
Merged PRs (30d)
11

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from labthings/labthings-fastapi

All issues in labthings/labthings-fastapi

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.