[Cython] cython-0.23 monkey-patches stdlib?

Stefan Behnel stefan_ml at behnel.de
Mon Jun 29 21:34:44 CEST 2015


Stefan Behnel schrieb am 06.06.2015 um 22:25:
> Neal Becker schrieb am 06.06.2015 um 20:25:
>> According to
>> https://github.com/cython/cython/blob/master/CHANGES.rst
>>
>> the default build would attempt to modify python stdlib files?
> 
> No. Glad you asked, that might not be clear.
> 
> It will not modify the *files*, only the content of the modules after
> importing them. It adds the missing ABCs to the collections.abc module and
> registers Cython's own types with them *at runtime*. Here's what it does:
> 
> https://github.com/cython/cython/blob/bb0dec2/Cython/Utility/Coroutine.c#L1322
> 
> This is a bit fragile, like all monkey-patching. As long as things get
> imported in the right order, it works. But if you import asyncio before a
> Cython module that adds the ABCs, it may already have decided that the ABCs
> don't exist and won't use them. That's controllable on user application
> side, though.
> 
> Also, the first patcher necessarily wins, so if there will ever be updates
> to the ABCs, old Cython modules would still patch in the old versions when
> imported first. They should tend to be quite stable, though.
> 
> In any case, this will get better over time as more code switches to Py3.5
> and later.

Given the drawbacks above, I decided to extract the ABC patching into a
separate PyPI module that users can install themselves to enable
interoperability.

https://pypi.python.org/pypi/backports_abc

I'll remove the ABC patching code from Cython again.

Stefan



More information about the cython-devel mailing list