8000 Cython 3.1 compatibility · Issue #1575 · python-zeroconf/python-zeroconf · GitHub
[go: up one dir, main page]

Skip to content

Cython 3.1 compatibility #1575

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mgorny opened this issue May 3, 2025 · 4 comments
Closed

Cython 3.1 compatibility #1575

mgorny opened this issue May 3, 2025 · 4 comments

Comments

@mgorny
Copy link
Contributor
mgorny commented May 3, 2025

Cython 3.1.0 is in RC phase already, so we can expect a final release sooner than later. As #1559 shows, zeroconf currently doesn't work with it and I wasn't able to find any tracking issue for the issues.

I have been trying to fix it myself but I'm afraid it's above my pay grade. From what I gather, Cython 3.1 got better at type annotations in .py files, and all the issues I've hit were somehow related to type annotations.

I've filed #1574 to fix one case of low-hanging fruit.


Another issue I've noticed is the type mismatch in DNSRecord.ttl:

cdef class DNSRecord(DNSEntry):
cdef public cython.float ttl

class DNSRecord(DNSEntry):
"""A DNS record - like a DNS entry, but has a TTL"""
__slots__ = ("created", "ttl")
# TODO: Switch to just int ttl
def __init__(
self,
name: str,
type_: int,
class_: int,
ttl: float | int,
created: float | None = None,
) -> None:
self._fast_init_record(name, type_, class_, ttl, created or current_time_millis())


Other signature mismatches I couldn't grasp. It is possible that they are actually a bug in Cython, but I don't really know Cython, so I'd appreciate if someone with better understanding of it checked, and possibly reported a bug upstream.

FWICS I can reproduce the same error with the following minimal reproducer:

.pxd:

cdef void foo(object x);

.py:

def foo(x: int) -> None:
    ...

but I don't know how int is supposed to be mapped here.

@bdraco
Copy link
Member
bdraco commented May 3, 2025

I have ~16 projects that I’m working on that don’t work with 3.1.x. I’m working through the smaller ones first. It’s going to take a while to get here. If it ships before I get to it, I’ll do a new release to pin Cython

@bdraco
Copy link
Member
bdraco commented May 3, 2025

We use object when we don’t want Cython to convert it to a native type and we want a PyInt.

Usual workaround it to assign the type to _int = int and than change the type to _int. That has prevented Cython from converting it

@mgorny
Copy link
Contributor Author
mgorny commented May 3, 2025

There's also the possibility of using "annotation_typing": False directive, but that's a kind of big cannon.

@bdraco
Copy link
Member
bdraco commented May 3, 2025

Fixed in master, release pending

@bdraco bdraco closed this as completed May 3, 2025
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

No branches or pull requests

2 participants
0