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

Use pydantic instead of dicts

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

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
25/100
Issue 类型
功能
描述清晰度
需要澄清
活跃度
停滞
技术栈
python

调研方向

首先检查现有的事件内容 dict 以及 commit 59136e4 中的 ArtC 事件实现,然后审查事件的创建和反序列化方式。在尝试进行更改之前,先定义生成的 Pydantic 模型和事件版本兼容性应如何工作;完成意味着设计解决了旧版本的反序列化问题,并保留或有意更改基于 dict 的使用方式。

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

描述

Description

Instead of just storing the event contents as three anonymous dicts we should use pydantic to allow proper typed instance attributes. I tried it out with the ArtC event in https://github.com/magnusbaeck/eiffel-pythonlib/commit/59136e4188914ec8530ba658cef1b2e64f1ba185. Writing these classes by hand is rather boring so we should explore using github.com/koxudaxi/datamodel-code-generator to generate the code.

Motivation

Typed classes would enable linters and IDEs to help out when writing code that accesses events.

Exemplification

I'd expect any piece of code that creates events would be easier to write. Reasonable people may disagree, but pydantic-based classes can be initialized from a dict so you could continue working with dicts if you prefer (but the syntax would be slightly different so it would break backwards compatibility).

Benefits

See Motivation, above.

Possible Drawbacks

It's not clear how we should deal with different versions of the events. When producing events we can probably just use the latest known version, but what do we do when deserializing events of old versions? They might not be acceptable to the current version of the schema (which is what the pydantic model would contain). Should we version the event classes too, when necessary?

主要语言
Python
星标
8
派生
12
PR 合并指标
30 天内没有已合并 PR

环境准备

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

从这里开始

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

eiffel-community/eiffel-pythonlib 的其他 Issue

查看 eiffel-community/eiffel-pythonlib 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

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