fix: build with cython 3.3.0 by bdraco · Pull Request #1820 · python-zeroconf/python-zeroconf · GitHub
Skip to content

fix: build with cython 3.3.0 - #1820

Merged
bdraco merged 2 commits into
masterfrom
fix-cython-330
Aug 28, 2026
Merged

bdraco merged 2 commits into
masterfrom
fix-cython-330

Conversation

@bdraco

@bdraco bdraco commented Aug 26, 2026

Copy link
Copy Markdown
Member

Summary

Cython 3.3.0 now resolves subscripted annotations like list[str] or set[DNSPointer] when it knows the inner type, then rejects them as incompatible with the plain list/set/dict declarations in the .pxd; seven modules fail to build. It also treats an annotated local that is listed in a .pxd @cython.locals as a redeclaration.

The fix routes each failing annotation through an alias Cython cannot resolve, the same _str = str idiom the codebase already uses, so the annotation degrades to the plain container and the .pxd stays the single source of truth; mypy still sees the full types through the aliases. The three conflicting locals (query_buckets, next_scheduled, known_answers_set) keep their Python annotations and drop their @cython.locals entries, which declared the same types.

Details

  • On Cython 3.2.9 (the locked version) the generated C for every function body is identical to master after normalizing line numbers; the only additions are the module level alias bindings executed once at import.
  • Argument checks are unchanged, for example unique_types still compiles to __Pyx_ArgTypeTest(..., 0, "unique_types", 2), and the Py_None guard counts per module are identical, so no new None checks landed in the hot paths.
  • The annotated HTML from cython -a shows every pre existing source line keeps its exact score on both 3.2.9 and 3.3.0; only the new alias lines add score, at import time.

Test plan

  • all 18 TO_CYTHONIZE modules compile with Cython 3.3.0 and 3.2.9
  • full pytest suite passes with extensions built by 3.2.9 and by 3.3.0
  • pre-commit (ruff, mypy, flake8, cython-lint) passes

Fixes #1818

@bdraco

bdraco commented Aug 26, 2026

Copy link
Copy Markdown
Member Author

@bdraco
bdraco marked this pull request as ready for review August 26, 2026 15:13
@bluetoothbot

Copy link
Copy Markdown
Contributor

@bdraco: perf and html look the same so should be good to go if ci passes

Confirmed on my read — no runtime behavior change, only annotations and .pxd declarations.

Two return annotations look unnecessary. browser.py:268 and registry.py:83. Siblings browser.py:227, _cache.py:185, registry.py:79 keep plain list[DNSOutgoing] / list[DNSRecord] / list[ServiceInfo] against the same list pxd declarations, with inner types cimported, and compile. DNSOutgoing_ serves only line 268.

One gap on "if CI passes": CI won't build with 3.3.0. poetry.lock:291 pins 3.2.9, and the use_cython matrix installs from the lock. Only build_wheels resolves Cython>=3.0.8 unpinned, and it runs after release against master. Run poetry update cython here so the matrix compiles what this PR fixes.

@bluetoothbot

Copy link
Copy Markdown
Contributor

@bluetoothbot bluetoothbot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tip

No blocking issues found — ready to merge.

@bdraco
bdraco merged commit df947b2 into master Aug 28, 2026
6 of 35 checks passed
@bdraco
bdraco deleted the fix-cython-330 branch August 28, 2026 14:39
netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this pull request Aug 28, 2026
## v0.150.2 (2026-08-28)

### Bug Fixes

- Keep `key=` distinct from a valueless `key` in TXT records
  ([#1813](python-zeroconf/python-zeroconf#1813),
  [`899eaaa`](python-zeroconf/python-zeroconf@899eaaa))


## v0.150.1 (2026-08-28)

### Bug Fixes

- Build with cython 3.3.0 ([#1820](python-zeroconf/python-zeroconf#1820),
  [`df947b2`](python-zeroconf/python-zeroconf@df947b2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0.150.0: cython 3.3.0 breaks build

2 participants