Conformance test: make dataclass_hash.py not rely on `typing.Hashable`?
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 3/5
- Tempo estimado
- 1-2 dias
- Facilidade para iniciantes
- 35/100
- Tipo de issue
- Refatoração
- Clareza
- Razoavelmente clara
- Status de atividade
- Estagnada
- Stack de tecnologia
- python
- Domínio
- testing-qa
Direção de pesquisa
Comece com conformance/tests/dataclasses_hash.py e compare suas assertions baseadas em Hashable com o comportamento de hash de dataclass descrito na issue. Leia as anotações referenciadas de typing.Hashable e object e, em seguida, revise as expectativas de conformance existentes. O trabalho estará concluído quando o teste verificar diretamente o resultado de dataclass hash sem depender da definição de Hashable do typeshed.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
I noticed that the conformance test currently enforces a hashability check on dataclasses:
https://github.com/python/typing/blame/6d5c186ea3f45dd80dcad9f172479b270e54966a/conformance/tests/dataclasses_hash.py
If we take the annotation of typing.Hashable and the annotation of object literally, then no type errors should be reported on that file, as typing.Hashable is a protocol that requires a def __hash__(self) -> int method, and object satisfies that protocol regardless of whether the dataclass transform creates its own __hash__ method or not.
I understand that the issue of deciding whether an object is hashable or not in type checkers is a tricky business and there was a lot of pre-existing discussions/proposals around it. This makes me wonder if it's worth doing a dedicated "hashability" section in the spec, and use separate conformance tests to establish how typing.Hashable assignability should be handled. My understanding is that the pre-existing dataclass hash tests is intended to just test about whether the __hash__ method is nullified or not under the dataclass transform, but by testing it via typing.Hashable it kinds of indirectly dictate hashable assignment behaviors as a side effect.
Concretely, what I had in mind was a refactor to dataclasses_hash.py, where we change the current assertions of the form
# This should generate an error because DC1 isn't hashable.
v: Hashable = DC(0)
into something like this:
assert_type(DC(0).__hash__, NoneType) # OK
The new version does not depend on how typing.Hashable gets defined in typeshed, and it (arguably) aligns more directly with the intention of the tests. But I am unsure about how controversial this proposal would be and hence want to get some feedback on it first.
- Linguagem predominante
- Python
- Estrelas
- 1.8k
- Forks
- 302
- Merge médio
- 23h
- PRs com merge (30d)
- 8
Guia de contribuição
Nenhum guia de contribuição indexado para este repositório
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
-
topic: typing spec
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 75/100
-
topic: documentation
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
-
topic: documentation
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 65/100
-
topic: conformance tests topic: typing spec
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 72/100
Todas as issues de python/typing
Issues semelhantes
-
area: harness bug status: needs-triage
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 75/100
Human-Agent-Society/reef#625 ·
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 70/100
-
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 80/100
learningequality/kolibri#15351 · 2 comentários ·
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 75/100
-
Name consistency Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 75/100
eellak/triplestore#65 · 1 comentário ·