跳到正文
Hacker News· ariebovenberg·· 12 天前AI 评分22

Pendulum 为何写出 Python 中最"邪门"的 "+" 运算符

Why Pendulum had to write the most cursed "+" operator in all of Python

AI 导读

Pendulum 为让日期时间与 timedelta 的加法符合直觉,重写了 Python 的 "+" 运算符,被作者称为 Python 中最"邪门"的实现。该实现需同时处理 datetime、date、time、Duration 与 timedelta 等多种类型组合,并兼顾时区与夏令时等边界情况。

来源:Hacker News · dev.arie.bovenberg.net