C
Chris Leary
As I understand it, the appeal of properties (and descriptors in
general) in new-style classes is that they provide a way to
"intercept" direct attribute accesses. This lets us write more clear
and concise code that accesses members directly without fear of future
API changes.
I love this feature of the language, but find that I still have to
call getter/setter methods of module instances. Since module
attributes are accessed by way of __dict__ and the module type has a
valid __mro__, why doesn't the descriptor protocol apply to module
instances?
TIA!
P.S. There is some previous discussion in comp.lang.python about using
a module like a new-style class.
http://groups.google.com/group/comp...t&q= Module+level+descriptors+or+properties
http://groups.google.com/group/comp.../49d0087c269b8296?lnk=gst&q=module+properties
http://groups.google.com/group/comp...7c/1690e6ddfbb257c7?lnk=gst&q=module+__call__
The suggested solution is always to provide a class wrapper in the
module itself, and have the module-user instantiate it appropriately.
This is a valid solution, but doesn't ensure that the client will use
it (the descriptor protocol does, as a feature of the language). As a
result, changes like these can break existing code that uses the
module.
general) in new-style classes is that they provide a way to
"intercept" direct attribute accesses. This lets us write more clear
and concise code that accesses members directly without fear of future
API changes.
I love this feature of the language, but find that I still have to
call getter/setter methods of module instances. Since module
attributes are accessed by way of __dict__ and the module type has a
valid __mro__, why doesn't the descriptor protocol apply to module
instances?
TIA!
P.S. There is some previous discussion in comp.lang.python about using
a module like a new-style class.
http://groups.google.com/group/comp...t&q= Module+level+descriptors+or+properties
http://groups.google.com/group/comp.../49d0087c269b8296?lnk=gst&q=module+properties
http://groups.google.com/group/comp...7c/1690e6ddfbb257c7?lnk=gst&q=module+__call__
The suggested solution is always to provide a class wrapper in the
module itself, and have the module-user instantiate it appropriately.
This is a valid solution, but doesn't ensure that the client will use
it (the descriptor protocol does, as a feature of the language). As a
result, changes like these can break existing code that uses the
module.