1.1 --- a/encoders.py Tue Apr 11 21:50:39 2017 +0200
1.2 +++ b/encoders.py Mon May 01 23:35:01 2017 +0200
1.3 @@ -209,7 +209,7 @@
1.4 )
1.5
1.6 attribute_ops = attribute_loading_ops + (
1.7 - "__store_via_object",
1.8 + "__store_via_class", "__store_via_object",
1.9 )
1.10
1.11 checked_loading_ops = (
2.1 --- a/templates/ops.c Tue Apr 11 21:50:39 2017 +0200
2.2 +++ b/templates/ops.c Mon May 01 23:35:01 2017 +0200
2.3 @@ -85,6 +85,11 @@
2.4 return 1;
2.5 }
2.6
2.7 +int __store_via_class__(__ref obj, int pos, __attr value)
2.8 +{
2.9 + return __store_via_object__(__get_class(obj), pos, value);
2.10 +}
2.11 +
2.12 int __get_class_and_store__(__ref obj, int pos, __attr value)
2.13 {
2.14 /* Forbid class-relative assignments. */
3.1 --- a/templates/ops.h Tue Apr 11 21:50:39 2017 +0200
3.2 +++ b/templates/ops.h Mon May 01 23:35:01 2017 +0200
3.3 @@ -44,9 +44,11 @@
3.4
3.5 /* Direct storage operations. */
3.6
3.7 +int __store_via_class__(__ref obj, int pos, __attr value);
3.8 int __store_via_object__(__ref obj, int pos, __attr value);
3.9 int __get_class_and_store__(__ref obj, int pos, __attr value);
3.10
3.11 +#define __store_via_class(OBJ, ATTRNAME, VALUE) (__store_via_class__(OBJ, __ATTRPOS(ATTRNAME), VALUE))
3.12 #define __store_via_object(OBJ, ATTRNAME, VALUE) (__store_via_object__(OBJ, __ATTRPOS(ATTRNAME), VALUE))
3.13 #define __get_class_and_store(OBJ, ATTRNAME, VALUE) (__get_class_and_store__(OBJ, __ATTRPOS(ATTRNAME), VALUE))
3.14
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/tests/lambda.py Mon May 01 23:35:01 2017 +0200
4.3 @@ -0,0 +1,17 @@
4.4 +f = lambda x: (x, 1)
4.5 +
4.6 +class C:
4.7 + f = lambda x: (x, 2)
4.8 +
4.9 +print f(123) # (123, 1)
4.10 +
4.11 +c = C()
4.12 +print c.f # __main__.C.$l0
4.13 +print c.f(123) # (123, 2)
4.14 +
4.15 +c.f = f
4.16 +print c.f(123) # (123, 1)
4.17 +
4.18 +C.f = f
4.19 +c2 = C()
4.20 +print c2.f(123) # (123, 1)