Can't use a subscripted `ThingSlot`

Abierto
#417 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 3 días

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
55/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
fastapi, python
Área
backend

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
Python
Estrellas
10
Forks
4
Merge medio
4 d 15 h
PR fusionados (30 d)
11

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de labthings/labthings-fastapi

Todos los issues de labthings/labthings-fastapi

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.