Glad somebody is watching what I'm doing here -- I was afraid I was having too much fun by myself! :-) > -------- Original Message -------- > Log Message: > > Make attributes of subtypes writable, but only for dynamic subtypes > derived in Python using a class statement; static subtypes derived in > C still have read-only attributes. > -------- Original Message -------- > > I would like to argue that "plain old C types" should act as if they > have __dict__s for consistency with other types. Good point. Plain old types currently (in the descr-branch) have a readonly dict (using a proxy) and no settable attributes. I will probably give types settable attributes in a next revision, but I prefer not to make the type's dict writable -- I need to be able to watch the setattr calls so that if someone changes DictType.__getitem__ I can change the mp_subscript to a C function that calls the __getitem__ method. For speed reasons, if you don't override them, the C tp_slot functions carry out the operation directly, and the __slot__ methods call the C tp_slot functions; but when __slot__ is overridden, tp_slot must call __slot__. > It is sometimes useful > to be able to annotate objects by adding attributes to them. But this > only works with class instance objects, not instances of types. > > Paul Prescod If you're talking about *instances*: instances of subtypes of built-in types have a dict of their own to which you can add stuff to your heart's content. Instances of built-in types will continue not to have a dict (it would cost too much space if *every* object had a dict, even if it was a NULL pointer when no attrs are defined). If you mean you want to annotate types like you can annotate classes, that should be possible once I implement what I describe above. --Guido van Rossum (home page: http://www.python.org/~guido/)
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4