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