Commit 4a196738 authored by Stefan Behnel's avatar Stefan Behnel

Switch off all special methods for closure classes the hard way.

parent 753e262f
...@@ -367,6 +367,8 @@ class ConstructorSlot(InternalMethodSlot): ...@@ -367,6 +367,8 @@ class ConstructorSlot(InternalMethodSlot):
self.method = method self.method = method
def slot_code(self, scope): def slot_code(self, scope):
if scope.is_closure_class_scope:
return "0"
if (self.slot_name != 'tp_new' if (self.slot_name != 'tp_new'
and scope.parent_type.base_type and scope.parent_type.base_type
and not scope.has_pyobject_attrs and not scope.has_pyobject_attrs
...@@ -398,6 +400,8 @@ class SyntheticSlot(InternalMethodSlot): ...@@ -398,6 +400,8 @@ class SyntheticSlot(InternalMethodSlot):
self.default_value = default_value self.default_value = default_value
def slot_code(self, scope): def slot_code(self, scope):
if scope.is_closure_class_scope:
return "0"
if scope.defines_any(self.user_methods): if scope.defines_any(self.user_methods):
return InternalMethodSlot.slot_code(self, scope) return InternalMethodSlot.slot_code(self, scope)
else: else:
......
...@@ -6,8 +6,27 @@ ...@@ -6,8 +6,27 @@
def func(): def func():
""" """
>>> funcs = func() >>> funcs = func()
>>> [f(1) for f in funcs] >>> [f(1) for f in funcs] # doctest: +NORMALIZE_WHITESPACE
['eq', 'str', 'weakref', 'new', 'dict'] ['eq',
'str',
'weakref',
'new',
'getitem',
'setitem',
'delitem',
'getslice',
'setslice',
'delslice_',
'getattr',
'getattribute',
'setattr',
'delattr',
'get',
'set',
'delete',
'dict',
'dealloc',
'cinit']
""" """
def __eq__(a): def __eq__(a):
return 'eq' return 'eq'
...@@ -21,19 +40,77 @@ def func(): ...@@ -21,19 +40,77 @@ def func():
def __new__(a): def __new__(a):
return 'new' return 'new'
def __getitem__(a):
return 'getitem'
def __setitem__(a):
return 'setitem'
def __delitem__(a):
return 'delitem'
def __getslice__(a):
return 'getslice'
def __setslice__(a):
return 'setslice'
def __delslice__(a):
return 'delslice_'
def __getattr__(a):
return 'getattr'
def __getattribute__(a):
return 'getattribute'
def __setattr__(a):
return 'setattr'
def __delattr__(a):
return 'delattr'
def __get__(a):
return 'get'
def __set__(a):
return 'set'
def __delete__(a):
return 'delete'
def __dict__(a): def __dict__(a):
return 'dict' return 'dict'
def __setitem__(x): def __dealloc__(a):
return '__setitem__' return 'dealloc'
def __getslice__(x): def __cinit__(a):
return '__getslice__' return 'cinit'
def list_from_gen(g): def list_from_gen(g):
return list(g) return list(g)
# move into closure by using inside of generator expression # move into closure by using inside of generator expression
return list_from_gen( return list_from_gen([
[__eq__, __str__, __weakref__, __new__, __dict__, __setitem__, __getslice__][i] __eq__,
for i in range(5)) __str__,
__weakref__,
__new__,
__getitem__,
__setitem__,
__delitem__,
__getslice__,
__setslice__,
__delslice__,
__getattr__,
__getattribute__,
__setattr__,
__delattr__,
__get__,
__set__,
__delete__,
__dict__,
__dealloc__,
__cinit__,
][i] for i in range(20))
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