Author: Ronan Lamy <[email protected]>
Branch: refactor-slots
Changeset: r92561:9b482bc4eb37
Date: 2017-10-02 16:12 +0200
http://bitbucket.org/pypy/pypy/changeset/9b482bc4eb37/
Log: Extract make_unary_slot()
diff --git a/pypy/module/cpyext/slotdefs.py b/pypy/module/cpyext/slotdefs.py
--- a/pypy/module/cpyext/slotdefs.py
+++ b/pypy/module/cpyext/slotdefs.py
@@ -455,15 +455,7 @@
('tp_iter', '__iter__'),
]:
if name == tp_name:
- slot_fn = w_type.lookup(attr)
- if slot_fn is None:
- return
-
- @slot_function([PyObject], PyObject)
- @func_renamer("cpyext_%s_%s" % (name.replace('.', '_'),
typedef.name))
- def slot_func(space, w_self):
- return space.call_function(slot_fn, w_self)
- handled = True
+ return make_unary_slot(space, typedef, name, attr)
for tp_name, attr in [('tp_hash', '__hash__'),
('tp_as_sequence.c_sq_length', '__len__'),
@@ -693,6 +685,18 @@
return slot_func
+def make_unary_slot(space, typedef, name, attr):
+ w_type = space.gettypeobject(typedef)
+ slot_fn = w_type.lookup(attr)
+ if slot_fn is None:
+ return
+
+ @slot_function([PyObject], PyObject)
+ @func_renamer("cpyext_%s_%s" % (name.replace('.', '_'), typedef.name))
+ def slot_func(space, w_self):
+ return space.call_function(slot_fn, w_self)
+ return slot_func
+
@slot_factory('tp_descr_set')
def make_tp_descr_set(space, typedef):
w_type = space.gettypeobject(typedef)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit