Getting back into the Python mood, I figured I’d brush up on some things that’ve been added to the language since I left it. IronPython, a bridge between the CLR/.NET Framework and the Python language, just released version 1.0 last week. The first thing I wanted to do was port the UI for an instant messaging app that scripts Outlook for back-end communications. Now, I’d heard about the new decorator syntax, so I wanted to use that to describe the controls that would be added to a form:
class InstantOutlook(BaseForm):
@control
def users(self):
ctrl = WinForms.ListBox()
# init ctrl
return ctrl
The catch here is that the control decorator marks the method as a control initializer. The decorator would have to take care of ensuring that the initialization code was only run once, and that the result of the initializer was added to the form’s Controls collection.
I soon found out that there’s no such thing as method decoration! The object passed to my decorator was a function, which means that I can’t make decisions about methods using their class as context. Oy!
It was pretty much a bee-line from this problem to metaclasses. So far, I’ve grok’ed that metamethods (methods on a metaclass) run orthogonal to inheritance. I haven’t yet seen much use for that. But a metaclass does give me a chance to customize the construction of a class:
class metatype(type):
def __new__(cls, name, bases, dict):
dict = delayed.apply(cls, dict)
return type.__new__(cls, name, bases, dict)
...More coming soon…
One Comment
1 Mark Host wrote:
You seem generally more motivated and happy since you made the move. Congrats!