Movatterモバイル変換


[0]ホーム

URL:


[Python-ideas] Fwd: Detecting Attribute Updates on Objects

Gustavo Rehermanngugurehermann at gmail.com
Fri Feb 17 13:43:13 EST 2017


Whoops, I forgot to subscribe before. Seems like now I'm able to send thisidea, so let's try again :)================According to this idea, the interpreter calls a function on an object Oeverytime an attribute A of it changes, recursing through objects thatcontain O as attribute as well. Avoiding loops too (refer to P3 below).Explanation:P1. When setting any property of an object inside a property, theinterpreter should also call "__update_attr__(self, attr_name, old_item,new_item)" in the object that contains it. This automatically calls thesame thing on every object that contains this one too, until a loop is hit(see P3), which makes it possible for a perfect dict synchronization with afile or stuff like that. This should also work for lists and any kind ofobject that contains attributes; so for every object O that contains A asattribute, whenever updating any of A's attributse call __update_attr__()or something on O.P2. From here on, refer as parents to any objects which contain the currentobject as attribute.P3. Python internally stores a cache - a tree of references - to speed upthe process. if __update_attr__ finds a loop then it stops at the topcontainer and instead sends it a call __update_loop__(). Whenever either orboth __update_attr__ or __update_loop__() functions are overwritten by anon-function, the interpreter skips that call in the tree (see P5).P4. To save on performance, the interpreter first checks the__detect_update__ attribute of the class (it is a single-byte int/ctypeschar, and is used as a bit mask): if bit 1 is OFF, then proceed the calls;otherwise, skip this and go to the parents in the tree (or don't call__update_loop__ at all if the call was about an update loop); if bit 2 isON, then don't iterate on the parent; otherwise proceed to every parents asnormal.P5. Bit 3 is only accessible from an interpreter (any attempt to change itwill have the interpreter change it back to what it was before), and whenON forces the interpreter to skip this object or stop iterating, dependingon Bit 2. This bit has precedence over Bit 1 and is ON always if__update_attr__ is a non-function. Other bits are ignored.P6. By default __detect_update__ is b10 on both bytes, or b00 if thefunction was overwritten by another function.Thank you,Gustavo Ramos "Gustavo6046" Rehermann-------------- next part --------------An HTML attachment was scrubbed...URL: <http://mail.python.org/pipermail/python-ideas/attachments/20170217/1b8b90e8/attachment-0001.html>


More information about the Python-ideasmailing list

[8]ページ先頭

©2009-2026 Movatter.jp