Commit 50a0470d authored by scoder's avatar scoder

Merge pull request #38 from vitek/_bindings

CyFunction
parents 508ee78a 80579d55
This diff is collapsed.
...@@ -1869,8 +1869,8 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -1869,8 +1869,8 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code.putln("%s = PyTuple_New(0); %s" % (Naming.empty_tuple, code.error_goto_if_null(Naming.empty_tuple, self.pos))); code.putln("%s = PyTuple_New(0); %s" % (Naming.empty_tuple, code.error_goto_if_null(Naming.empty_tuple, self.pos)));
code.putln("%s = PyBytes_FromStringAndSize(\"\", 0); %s" % (Naming.empty_bytes, code.error_goto_if_null(Naming.empty_bytes, self.pos))); code.putln("%s = PyBytes_FromStringAndSize(\"\", 0); %s" % (Naming.empty_bytes, code.error_goto_if_null(Naming.empty_bytes, self.pos)));
code.putln("#ifdef %s_USED" % Naming.binding_cfunc) code.putln("#ifdef __Pyx_CyFunction_USED")
code.putln("if (%s_init() < 0) %s" % (Naming.binding_cfunc, code.error_goto(self.pos))) code.putln("if (__Pyx_CyFunction_init() < 0) %s" % code.error_goto(self.pos))
code.putln("#endif") code.putln("#endif")
code.putln("/*--- Library function declarations ---*/") code.putln("/*--- Library function declarations ---*/")
......
...@@ -2047,8 +2047,8 @@ static PyObject* __Pyx_Method_ClassMethod(PyObject *method) { ...@@ -2047,8 +2047,8 @@ static PyObject* __Pyx_Method_ClassMethod(PyObject *method) {
else if (PyCFunction_Check(method)) { else if (PyCFunction_Check(method)) {
return PyClassMethod_New(method); return PyClassMethod_New(method);
} }
#ifdef __pyx_binding_PyCFunctionType_USED #ifdef __Pyx_CyFunction_USED
else if (PyObject_TypeCheck(method, __pyx_binding_PyCFunctionType)) { /* binded CFunction */ else if (PyObject_TypeCheck(method, __pyx_CyFunctionType)) {
return PyClassMethod_New(method); return PyClassMethod_New(method);
} }
#endif #endif
......
...@@ -433,6 +433,7 @@ class CythonCompileTestCase(unittest.TestCase): ...@@ -433,6 +433,7 @@ class CythonCompileTestCase(unittest.TestCase):
from Cython.Compiler import Options from Cython.Compiler import Options
self._saved_options = [ (name, getattr(Options, name)) self._saved_options = [ (name, getattr(Options, name))
for name in ('warning_errors', 'error_on_unknown_names') ] for name in ('warning_errors', 'error_on_unknown_names') ]
self._saved_default_directives = Options.directive_defaults.items()
Options.warning_errors = self.warning_errors Options.warning_errors = self.warning_errors
if self.workdir not in sys.path: if self.workdir not in sys.path:
...@@ -442,6 +443,7 @@ class CythonCompileTestCase(unittest.TestCase): ...@@ -442,6 +443,7 @@ class CythonCompileTestCase(unittest.TestCase):
from Cython.Compiler import Options from Cython.Compiler import Options
for name, value in self._saved_options: for name, value in self._saved_options:
setattr(Options, name, value) setattr(Options, name, value)
Options.directive_defaults = dict(self._saved_default_directives)
try: try:
sys.path.remove(self.workdir) sys.path.remove(self.workdir)
...@@ -849,6 +851,7 @@ class CythonPyregrTestCase(CythonRunTestCase): ...@@ -849,6 +851,7 @@ class CythonPyregrTestCase(CythonRunTestCase):
CythonRunTestCase.setUp(self) CythonRunTestCase.setUp(self)
from Cython.Compiler import Options from Cython.Compiler import Options
Options.error_on_unknown_names = False Options.error_on_unknown_names = False
Options.directive_defaults['binding'] = True
def _run_unittest(self, result, *classes): def _run_unittest(self, result, *classes):
"""Run tests from unittest.TestCase-derived classes.""" """Run tests from unittest.TestCase-derived classes."""
......
# cython: binding=True
# mode: run
# tag: cyfunction
def test_dict():
"""
>>> test_dict.foo = 123
>>> test_dict.__dict__
{'foo': 123}
>>> test_dict.__dict__ = {'bar': 321}
>>> test_dict.__dict__
{'bar': 321}
>>> test_dict.func_dict
{'bar': 321}
"""
def test_name():
"""
>>> test_name.__name__
'test_name'
>>> test_name.func_name
'test_name'
>>> test_name.__name__ = 123 #doctest:+ELLIPSIS
Traceback (most recent call last):
TypeError: __name__ must be set to a ... object
>>> test_name.__name__ = 'foo'
>>> test_name.__name__
'foo'
"""
def test_doc():
"""
>>> del test_doc.__doc__
>>> test_doc.__doc__
>>> test_doc.__doc__ = 'docstring'
>>> test_doc.__doc__
'docstring'
>>> test_doc.func_doc
'docstring'
"""
def test_reduce():
"""
>>> import pickle
>>> pickle.loads(pickle.dumps(test_reduce))()
'Hello, world!'
"""
return 'Hello, world!'
def test_method(self):
return self
class BindingTest:
"""
>>> BindingTest.test_method = test_method
>>> BindingTest.test_method() #doctest:+ELLIPSIS
Traceback (most recent call last):
TypeError: ...
>>> BindingTest().test_method()
<BindingTest instance>
"""
def __repr__(self):
return '<BindingTest instance>'
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