Commit 5112e05f authored by Jason Madden's avatar Jason Madden

On Python 3.10, Cython types are not immutable. This broke gevent.local.

Change the way we detect compiled types to fix this.

Refs https://github.com/cython/cython/issues/4326
parent cbfd12d2
...@@ -581,16 +581,22 @@ def __new__(cls, *args, **kw): ...@@ -581,16 +581,22 @@ def __new__(cls, *args, **kw):
self.__cinit__(*args[1:], **kw) self.__cinit__(*args[1:], **kw)
return self return self
try: if local.__module__ == 'gevent.local':
# PyPy2/3 and CPython handle adding a __new__ to the class # PyPy2/3 and CPython handle adding a __new__ to the class
# in different ways. In CPython and PyPy3, it must be wrapped with classmethod; # in different ways. In CPython and PyPy3, it must be wrapped with classmethod;
# in PyPy2 < 7.3.3, it must not. In either case, the args that get passed to # in PyPy2 < 7.3.3, it must not. In either case, the args that get passed to
# it are stil wrong. # it are stil wrong.
local.__new__ = 'None' #
except TypeError: # pragma: no cover # Prior to Python 3.10, Cython-compiled classes were immutable and
# Must be compiled # raised a TypeError on assignment to __new__, and we relied on that
pass # to detect the compiled version; but that breaks in
else: # 3.10 as classes are now mutable. (See
# https://github.com/cython/cython/issues/4326).
#
# That's OK; post https://github.com/gevent/gevent/issues/1480, the Cython-compiled
# module has a different name than the pure-Python version and we can check for that.
# It's not as direct, but it works.
# So here we're not compiled
from gevent._compat import PYPY from gevent._compat import PYPY
from gevent._compat import PY2 from gevent._compat import PY2
if PYPY and PY2: if PYPY and PY2:
...@@ -606,6 +612,10 @@ else: ...@@ -606,6 +612,10 @@ else:
del PYPY del PYPY
del PY2 del PY2
else: # pragma: no cover
# Make sure we revisit in case of changes to the (accelerator) module names.
if local.__module__ != 'gevent._gevent_clocal':
raise AssertionError("Module names changed; revisit this code.")
_init() _init()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment