Conformance suite: Questionable tests in dataclasses_descriptors.py
Mantenedores costumam responder em até 1 dia
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 2/5
- Tempo estimado
- 1-3 horas
- Facilidade para iniciantes
- 48/100
- Tipo de issue
- Bug
- Clareza
- Razoavelmente clara
- Status de atividade
- Pouca atividade
- Stack de tecnologia
- python
- Domínio
- testing-qa
Direção de pesquisa
Leia conformance/tests/dataclasses_descriptors.py, concentrando-se nos casos Desc2 e DC2 descritos na issue. Verifique os tipos afirmados em relação ao comportamento em tempo de execução e aos resultados divergentes de pyrefly, mypy e pyright. Considera-se concluído quando a suíte de conformance não exigir mais um comportamento que não seja especificado ou compatível com o comportamento em tempo de execução, e a remoção proposta do teste tiver sido resolvida pelos mantenedores do projeto.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
The dataclasses_descriptors.py test case has a comment "This portion of the dataclass spec is under-specified in the documentation, but its behavior can be determined from the runtime implementation."
However, some of the behaviors in tests don't align with the runtime behavior.
The first part, which is using a data descriptor Desc1 and a dataclass DC1, is fine.
Then we get this, where Desc2 is a non-data descriptor (only implementing __get__):
@dataclass
class DC2:
x: Desc2[int]
y: Desc2[str]
z: Desc2[str] = Desc2()
assert_type(DC2.x, list[int])
assert_type(DC2.y, list[str])
assert_type(DC2.z, list[str])
However, DC2.x and DC2.y are AttributeErrors at runtime, because there is no Desc2 object in the runtime class dictionary. I don't know if we should require type checkers to produce an error but certainly we should allow it.
Then we construct a DC2 object:
dc2 = DC2(Desc2(), Desc2(), Desc2())
assert_type(dc2.x, int)
assert_type(dc2.y, str)
assert_type(dc2.z, str)
But at runtime, dc2's three attributes are all just those Desc2 objects, not ints or strs, because those objects are stored as instance attributes, so the descriptor protocol never runs on them.
The more complicated case is the z attribute, which has a Desc2 object stored in the class. Dataclasses would conventionally treat this as the default, but it gets the default by conventional access in the class body, which calls the descriptor's __get__ with obj=None. So the runtime default for this field is actually the value you'd get for accessing DC2.z, which is list[str].
Looking at actual type checker behavior, I think pyrefly gets all this pretty much right (which means it fails the test). Mypy and pyright pass the test, but their behavior is wrong.
Since (as the test acknowledges) the behavior is not fully specified, perhaps it is best to delete this test from the conformance suite for now, until we come up with a full specification for the behavior of descriptors in dataclasses.
- Linguagem predominante
- Python
- Estrelas
- 1.8k
- Forks
- 302
- Merge médio
- 20h 26min
- PRs com merge (30d)
- 10
Preparar o ambiente
Ainda não verificamos os arquivos de configuração deste projeto. Comece pelo README e veja nosso guia da primeira contribuição para os passos gerais.
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de python/typing
-
topic: typing spec
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
python/typing#2356 · 2 comentários · 1 reação ·
Mantenedores costumam responder em até 1 dia
-
topic: typing spec
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 75/100
Mantenedores costumam responder em até 1 dia
-
topic: documentation
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
python/typing#2227 · 2 comentários ·
Mantenedores costumam responder em até 1 dia
-
topic: documentation
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 65/100
python/typing#2150 · 2 comentários · 2 reações ·
Mantenedores costumam responder em até 1 dia
-
topic: conformance tests topic: typing spec
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 72/100
python/typing#2351 · 2 comentários ·
Mantenedores costumam responder em até 1 dia
Todas as issues de python/typing
Issues semelhantes
-
Broken links found in docsAbertadocs pydanty:is-working
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 75/100
pydantic/pydantic-ai#8863 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
run-llama/llama_index#23278 ·
Mantenedores costumam responder em até 2 dias
-
documentation from-review-extraction github-actions priority: low severity:nit
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 92/100
LearningCircuit/local-deep-research#6946 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 82/100
oracle/langchain-oracle#323 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 88/100
tenstorrent/tt-metal#58057 · 1 comentário ·
Mantenedores costumam responder em até 1 dia