Can't use a subscripted `ThingSlot`

Aperta
#417 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 3 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
55/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
fastapi, python
Ambito
backend

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Python
Stelle
10
Fork
4
Merge medio
4g 15h
PR unite (30g)
11

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di labthings/labthings-fastapi

Tutte le issue di labthings/labthings-fastapi

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.