Expanding on the default unpickling behavior of objects that do not implement __setstate__
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 3/5
- Tempo estimado
- 1-2 dias
- Facilidade para iniciantes
- 38/100
- Tipo de issue
- Documentação
- Clareza
- Razoavelmente clara
- Status de atividade
- Estagnada
- Stack de tecnologia
- python
- Domínio
- documentation
Direção de pesquisa
Comece pela seção da documentação que explica getstate, setstate e o comportamento durante a desserialização com pickle. Esclareça que estados na forma de tupla são aceitos, diferencie as atualizações diretas de dict para estado dinâmico das chamadas a setattr para estado com slots e explique o comportamento relevante sem depender da observação vaga existente.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
Documentation
I'm about to open a PR for it myself but I wanted to also open a related issue (just in case there are any objections)
Ever since Python 3.11, __getstate__'s default implementation has been added to object. With that change, the section explaining __getstate__ was expanded to also explain the default implementation in regards to slotted objects and the fact that their default state is a tuple of dicts (1 for the slotted dict and 1 optional dynamic dict) .
With this change, the user is now aware of the new concept of the "slotted state" and therefore should be aware of how it is handled when __setstate__ was not implemented. The current documentation states that the user may choose to implement __getstate__ and not __setstate__ so long as the returned state was a dict.
This needs to be updated to explain it also accepts tuples of the former format. Moreover, it should be updated to explain how do these 2 dicts differ in their setting behavior:
- The dynamic dict MUST be set using direct edit of the instance's
__dict__(in order to not activate__setattr__which is very important, especially on immutable instances that will throw an exception on such calls). This is behavior is similar to pure dict states (and should probably be documented as well) - The slotted dict MUST be set using calls to setattr (since they by definition do not exist on the instance
__dict__and therefore cannot be directly edited. Also we want to avoid accidentally a duplicate value on that dict)
Explaining this behavior will be more detailed and helpful than the current note that vaguely states:
At unpickling time, some methods like __getattr__(), __getattribute__(), or __setattr__() may be called upon the instance.
In case those methods rely on some internal invariant being true, the type should implement __new__() to establish such an invariant,
as __init__() is not called when unpickling an instance.
Explaining it will also prevent users from mistakenly relying on __setattr__ when they shouldn't. This will also prevents libraries like jsonpickle from incorrectly implementing their unpickling behavior to always use setattr (which causes bugs that arise from discrepancies with the default pickle library.
- Linguagem predominante
- Python
- Estrelas
- 77.2k
- Forks
- 36k
- Merge médio
- 1d 9h
- PRs com merge (30d)
- 558
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.
Mais de python/cpython
-
docs pending
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
-
stdlib type-feature
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
-
stdlib type-feature
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
-
build type-bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
-
stdlib topic-email type-feature
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 70/100
Todas as issues de python/cpython
Issues semelhantes
-
area/auth bug comp/agent P3 platform/discord type/security
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 88/100
NousResearch/hermes-agent#117848 ·
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 74/100
bancolombia/sentinel#23 ·
-
test md AbertaCI
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 74/100
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 74/100
langchain-ai/deepagents#6450 ·
-
bug client
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 88/100