docs: add cython gotchas section to CLAUDE.md#654
Merged
Conversation
Document the .py + .pxd traps that pass pure-Python (`SKIP_CYTHON=1`) CI but break or silently misbehave in the shipped Cython wheels: - cdef-typed module constants are not Python-importable (the trap hit on the `MAX_MESSAGE_SIZE` cap in #653 — needs the dual-name `MAX_X` / `_MAX_X` pattern). - `unsigned int` returned through `cdef int` can flip sign and bypass `< 0` sentinel branches — applies to any new uint32 decode in the marshaller/unmarshaller. - Sign-compare warnings in generated C predict the above class of bug; match signedness in the .pxd. - `noexcept` cdef paths must be pure C (no Python calls that can raise) — `_ustr_uint32` is the template. - `except *` adds a per-call `PyErr_Occurred()` check; watch CodSpeed when adding it to the hot path. - Module-level Python int constants force PyLong conversion; declare a cdef'd alias for hot-path use. - CodSpeed regressions only show on the Cython build — pure- Python tests can pass while production hot paths regress. Lessons distilled from PR #653 and from esphome/aioesphomeapi#1651 / #1653.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #654 +/- ##
==========================================
- Coverage 89.16% 89.10% -0.06%
==========================================
Files 29 29
Lines 3488 3488
Branches 602 602
==========================================
- Hits 3110 3108 -2
- Misses 228 229 +1
- Partials 150 151 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds a "Cython gotchas (things that have bitten us)" section to
CLAUDE.mdcapturing the non-obvious traps in the.py+.pxdsetup that work fine in pure-Python mode but break or silently misbehave in the shipped Cython wheels.Why
The pure-Python (
SKIP_CYTHON=1) CI leg is happy to sail past most of these — they only surface in theREQUIRE_CYTHON=1leg, the s390x leg, or in CodSpeed deltas. Worth writing down so the next contributor doesn't re-hit them on the marshaller/unmarshaller hot paths.Items captured:
cdef-typed module constants are not Python-importable (the trap hit on theMAX_MESSAGE_SIZEcap in fix(unmarshaller): cap message size at 128 MiB per d-bus spec #653 — needs the dual-nameMAX_X/_MAX_Xpattern).unsigned intreturned throughcdef intcan flip sign and bypass< 0sentinel branches — applies to any new uint32 decode in the marshaller/unmarshaller..pxd.noexceptcdef paths must be pure C —_ustr_uint32is the template.except *adds a per-callPyErr_Occurred()check; watch CodSpeed when adding it to the hot path.PyLong_AsLongper access; declare a cdef'd alias for hot-path use.Several of the lessons were distilled from upstream PRs esphome/aioesphomeapi#1651 and esphome/aioesphomeapi#1653, adapted to dbus-fast's marshaller/unmarshaller structure.
Documentation-only; no code changes, no tests needed.