Option to include `init=False` globally on a converter, not per class
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
Start with cattrs.Converter and the cattrs.strategies.include_init_false entry point mentioned in the issue, then inspect how converter configuration affects attrs classes. Verify the chosen global option with structure and unstructure examples containing init=False fields, and add coverage showing the old behavior is enabled for multiple classes.
由索引模型根据 Issue 内容生成。
描述
- cattrs version: v23.2.3
- Python version: 3.11.6
- Operating System: Ubuntu
Description
On previous cattrs versions, I used to structure and unstructure a lot of attrs classes that had many init=False fields.
Now, though, with the new versions of cattrs (v23.2.0), this behavior changed, breaking my code.
I'd like to be able to enable the old behavior back globally on a converter, instead of having to enable it for every single class, as I have many classes all over the place that would benefit from re-enabling init=False fields in conversion.
import attrs
import cattrs
@attrs.define
class Foo:
bar: int
baz: str = attrs.field(init=False)
foo = Foo(bar=1)
foo.baz = "hello"
converter = cattrs.Converter()
print(converter.unstructure(foo))
# before: {'bar': 1, 'baz': 'hello'}
# after: {'bar': 1}
I thought about something like this:
import cattrs
from cattrs.strategies import include_init_false
converter = cattrs.Converter()
include_init_false(converter)
# OR
converter = cattrs.Converter(include_init_false=True)
- 主要语言
- Python
- 星标
- 1.1k
- 派生
- 165
- 平均合并
- 16 小时 19 分钟
- 30 天内合并 PR
- 8
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
python-attrs/cattrs 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 72/100
python-attrs/cattrs#761 · 2 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 64/100
python-attrs/cattrs#513 · 4 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 35/100
python-attrs/cattrs#779 ·
维护者通常 1 天内回复
-
难度 3/5 1-2 天 新手友好度 85/100
python-attrs/cattrs#774 ·
维护者通常 1 天内回复
-
难度 5/5 一周以上 新手友好度 35/100
python-attrs/cattrs#746 · 2 条评论 ·
维护者通常 1 天内回复
查看 python-attrs/cattrs 的全部 Issue
相似的 Issue
-
bug server
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
sportsdataverse/sportsdataverse-py#641 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
googleapis/google-cloud-python#18532 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复