# HG changeset patch # User Paul Boddie # Date 1493674501 -7200 # Node ID 9c803c445939eccd41270df08bd304e4b8821b26 # Parent 30e58152063b8b08bf1f5fbef0872512700172cb Test lambda usage in class namespaces (differs from Python's behaviour). Added the __store_via_class operation. diff -r 30e58152063b -r 9c803c445939 encoders.py --- a/encoders.py Tue Apr 11 21:50:39 2017 +0200 +++ b/encoders.py Mon May 01 23:35:01 2017 +0200 @@ -209,7 +209,7 @@ ) attribute_ops = attribute_loading_ops + ( - "__store_via_object", + "__store_via_class", "__store_via_object", ) checked_loading_ops = ( diff -r 30e58152063b -r 9c803c445939 templates/ops.c --- a/templates/ops.c Tue Apr 11 21:50:39 2017 +0200 +++ b/templates/ops.c Mon May 01 23:35:01 2017 +0200 @@ -85,6 +85,11 @@ return 1; } +int __store_via_class__(__ref obj, int pos, __attr value) +{ + return __store_via_object__(__get_class(obj), pos, value); +} + int __get_class_and_store__(__ref obj, int pos, __attr value) { /* Forbid class-relative assignments. */ diff -r 30e58152063b -r 9c803c445939 templates/ops.h --- a/templates/ops.h Tue Apr 11 21:50:39 2017 +0200 +++ b/templates/ops.h Mon May 01 23:35:01 2017 +0200 @@ -44,9 +44,11 @@ /* Direct storage operations. */ +int __store_via_class__(__ref obj, int pos, __attr value); int __store_via_object__(__ref obj, int pos, __attr value); int __get_class_and_store__(__ref obj, int pos, __attr value); +#define __store_via_class(OBJ, ATTRNAME, VALUE) (__store_via_class__(OBJ, __ATTRPOS(ATTRNAME), VALUE)) #define __store_via_object(OBJ, ATTRNAME, VALUE) (__store_via_object__(OBJ, __ATTRPOS(ATTRNAME), VALUE)) #define __get_class_and_store(OBJ, ATTRNAME, VALUE) (__get_class_and_store__(OBJ, __ATTRPOS(ATTRNAME), VALUE)) diff -r 30e58152063b -r 9c803c445939 tests/lambda.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/lambda.py Mon May 01 23:35:01 2017 +0200 @@ -0,0 +1,17 @@ +f = lambda x: (x, 1) + +class C: + f = lambda x: (x, 2) + +print f(123) # (123, 1) + +c = C() +print c.f # __main__.C.$l0 +print c.f(123) # (123, 2) + +c.f = f +print c.f(123) # (123, 1) + +C.f = f +c2 = C() +print c2.f(123) # (123, 1)