Can't use a subscripted `ThingSlot`

Aberta
#417 0 comentários 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 3 dias

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
3/5
Tempo estimado
1-2 dias
Facilidade para iniciantes
55/100
Tipo de issue
Bug
Clareza
Razoavelmente clara
Status de atividade
Ativa
Stack de tecnologia
fastapi, python
Domínio
backend

Direção de pesquisa

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.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

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.

Linguagem predominante
Python
Estrelas
10
Forks
4
Merge médio
4d 15h
PRs com merge (30d)
11

Preparar o ambiente

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de labthings/labthings-fastapi

Todas as issues de labthings/labthings-fastapi

Issues semelhantes

Mais issues de Python

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.