Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Make a Converter without the default hook factories

未关闭
#793 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
25/100
Issue 类型
功能
描述清晰度
需要澄清
活跃度
活跃
技术栈
python
领域
backend

调研方向

The payload names no files. Start with the fallback-hook-factories section of the docs and the unstructure_fallback_factory and structure_fallback_factory arguments of Converter, to see how a child converter consults its parent. Then check why the default structure_attrs_fromdict preference overrides the parent's hook. The issue is open on which approach to take (a BaseConverter workaround or new __init__ flags), so agree on a design with maintainers first. Done means a child converter uses a hook registered on its parent even when a default hook exists.

由索引模型根据 Issue 内容生成。

描述

The problem

Let's take the fallback-hook-factories section

parent = Converter()

child = Converter(
    unstructure_fallback_factory=parent.get_unstructure_hook,
    structure_fallback_factory=parent.get_structure_hook,
)

Let's say in parent you added another custom hook factory such as

@parent.register_structure_hook_factory(lambda val: issubclass(val, Foo))
def structure_Foo(cls) -> StructureHook:
    ...

You would expect that the child would pick up this new converter of the parent, but that is not the case if there is already a way to structure Foo from the default converters in Converter

So what now?

One way around this is to use BaseConverter I guess, but it is not quite that straightforward and trying it out I still hit some other preferences that override it, e.g. structure_attrs_fromdict.

Another option would be to have flags in the __init__ of those converters to truely not add any defaults and let it fallback to the parent more directly.

主要语言
Python
星标
1.1k
派生
171
平均合并
14 小时 46 分钟
30 天内合并 PR
5

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

python-attrs/cattrs 的其他 Issue

查看 python-attrs/cattrs 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。