# Pendulum's "+" Operator Reads the Call Stack to Guess What You Mean

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

> Hacker News story 49976441 · language: en · submitted 2026-10-06
> Web version: https://zeli.app/story/49976441
> About this feed: https://zeli.app/llms.txt · Agent guide: https://zeli.app/skill.md

▲ 46 · by [ariebovenberg](<https://news.ycombinator.com/user?id=ariebovenberg>) · 💬 29
[original](<https://dev.arie.bovenberg.net/blog/pendulum-cursed-plus-operator/>) · [HN discussion](<https://news.ycombinator.com/item?id=49976441>)

## Summary

Pendulum, the popular Python datetime library, made two promises: DST-aware arithmetic and drop-in compatibility with the standard library. Those promises collide inside datetime.astimezone(), where the standard library calls + expecting wall-clock semantics. Pendulum's fix: inspect the call stack in __add__ and, if the caller is named astimezone, fall back to the standard library's behavior. The hack is fragile, breaks on PyPy and dateutil time zones, and makes + roughly 600 times slower. A merged pull request removes the guess.

## Key quote

> So you can change the result of + by renaming your own function.

## HN discussion (29 comments)

### [shoo](<https://news.ycombinator.com/item?id=49999015>)

> Mmm. Changing control flow based on introspection of the call stack is reasonably nasty.
>
> I recall we found a neat use for call stack introspection in one project - not to change control flow but to improve logging. Inside an open_db_connection utility function, to auto-generate an informational name describing which part of the codebase had opened the connection:
>
> E.g. some_backend_process:  main -> ... > grandparent -> parent -> open_db_connection
>
> We'd use information from the call stack generate a string "some_backend_process grandparent.parent" describing the call site which could be passed to postgres as the application_name [1] when establishing a connection. Then from the database side, if we had problematic queries at runtime, we had a lot more clues to figure out which part of the backend codebase was responsible [2].
>
> There'd be a way to do something equivalent without peeking at the call stack, by requiring the caller to explicitly pass a descriptive & unique name, but that makes things a bit more error-prone, especially since some devs would be prone to copy-pasting chunks of existing code & reusing the same name everywhere.
>
> [1] https://www.postgresql.org/docs/current/libpq-connect.html#L...
>
> [2] https://www.postgresql.org/docs/current/monitoring-stats.htm...

### [jvolkman](<https://news.ycombinator.com/item?id=49999286>)

> I'll one up this with my hack that changes the value of `sys.platform` based on the caller: https://github.com/jvolkman/rules_pycross/blob/main/pycross/...
>
> This is used when cross compiling binary wheels (e.g., building a macos wheel on a linux build host or vice versa).

### [ariebovenberg](<https://news.ycombinator.com/item?id=49976447>)

> Author here. I ran into this while comparing Pendulum with `whenever`, the datetime library I maintain. I sent a patch that removes the hack, but the post is about why the underlying design can't be patched the same way. Happy to answer questions.

---

## Cite

- Page: https://zeli.app/story/49976441
- Date: 2026-10-06
- Source: dev.arie.bovenberg.net (https://dev.arie.bovenberg.net/blog/pendulum-cursed-plus-operator/)
- Hacker News: https://news.ycombinator.com/item?id=49976441

## Other languages

- zh: https://zeli.app/zh/story/49976441 · markdown: https://zeli.app/zh/story/49976441.md
- ja: https://zeli.app/ja/story/49976441 · markdown: https://zeli.app/ja/story/49976441.md
- ko: https://zeli.app/ko/story/49976441 · markdown: https://zeli.app/ko/story/49976441.md
- de: https://zeli.app/de/story/49976441 · markdown: https://zeli.app/de/story/49976441.md
- es: https://zeli.app/es/story/49976441 · markdown: https://zeli.app/es/story/49976441.md
- ru: https://zeli.app/ru/story/49976441 · markdown: https://zeli.app/ru/story/49976441.md
