提交 54021bd7 authored 作者: Garming Sam's avatar Garming Sam

Remove usage of PyCapsule when running under PyPy

This type is unavailable in PyPy (and also unlikely to be exposed). This just removes a type-check.
上级 ce90645e
......@@ -7,6 +7,7 @@ Defines the `Type` class.
from __future__ import absolute_import, print_function, division
import ctypes
import platform
from six import string_types
......@@ -606,9 +607,11 @@ class Generic(SingletonType):
generic = Generic()
_cdata_type = ctypes.py_object.from_address(
ctypes.addressof(ctypes.pythonapi.PyCapsule_Type)).value
_cdata_type = None
if platform.python_implementation() != 'PyPy':
_cdata_type = ctypes.py_object.from_address(
ctypes.addressof(ctypes.pythonapi.PyCapsule_Type)).value
class _make_cdata(Op):
__props__ = ('rtype',)
......@@ -679,8 +682,12 @@ class CDataType(Type):
self.version = version
def filter(self, data, strict=False, allow_downcast=None):
if data is not None and not isinstance(data, _cdata_type):
# We ignore this type-check (_cdata_type is None) in PyPy
# because this type is not exposed to us.
if data is not None and _cdata_type is not None:
if not isinstance(data, _cdata_type):
raise TypeError("expected None or a PyCapsule")
return data
def _get_func(self):
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论