3.14 changes annotations behaviour for dataclasses.make_dataclass
Ninguém assumiu esta issue ainda.
- Linguagem predominante
- Python
- Estrelas
- 77.2k
- Forks
- 36k
- Métricas de merge de PRs
- Métricas de PR pendentes
Descrição
Bug report
Bug description:
I have many dataclasses created on demand by dataclasses.make_dataclass. 3.14 changes behaviour for instances of the dataclass.
In 3.13 and before, the instances have a __annotations__ attribute with the expected contents.
In 3.14, that attribute no longer exists, but calling instance.__annotate_func__ does return what was in __annotations__ before.
The 3.14 howto does say "you may access the annotations data member manually"
import dataclasses
import inspect
dc = dataclasses.make_dataclass("foo", (("one", int), ("two", str), ("three", complex)))
value = dc(1, 'hello', 3+4j)
print(f"{dir(value)=}")
try:
print(inspect.get_annotations(value))
except Exception as exc:
print("inspect.get_annotations exception: ", type(exc), exc)
if hasattr(dc, "__annotate_func__"):
print(f"{value.__annotate_func__()=}")
For Python 3.13:
dir(value)=['__annotations__', '__class__', '__dataclass_fields__', '__dataclass_params__ ....
For Python 3.14:
dir(value)=['__annotate_func__', '__annotations_cache__', '__class__', '__dataclass_fields__' ....
In both cases inspect.get_annotations() does give TypeError.
The release notes cover annotations, but nothing about changes to dataclasses instances.
Perhaps the annotations attributes shouldn't be on instances, but they have been. I also see __annotate_func__ on instances of regular objects from Python classes.
CPython versions tested on:
3.14, 3.13
Operating systems tested on:
Linux
Linked PRs
- gh-134387
- gh-134509
Guia de contribuição
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.
Direção de pesquisa
Comece pelo comportamento de dataclasses.make_dataclass e inspect.get_annotations descrito aqui e, em seguida, revise os PRs vinculados gh-134387 e gh-134509. Considera-se concluído quando o comportamento da 3.14 estiver resolvido ou explicitamente documentado de forma consistente com a comparação com a 3.13 e o annotations how-to.
Escrita pelo modelo de indexação a partir do texto da issue.
Avaliação
- Stack de tecnologia
- python
- Domínio
- backend
- Tipo de issue
- Bug
- Dificuldade
- 5/5
- Tempo estimado
- Mais de uma semana
- Status de atividade
- Estagnada
- Clareza
- Precisa de esclarecimento
- Facilidade para iniciantes
- 25/100