ctn-waterloo/nengo — pull request #302 by tbekolay (2014-03-29 00:56:11+00:00)
Title: Used Python magic to simplify Nengo objects

We've been using the special function ``make`` in networks, and started using ``initialize`` in other objects recently. This moves the things in those methods back into __init__ and instead makes sure that the right things happen by controlling object creation through new metaclasses: NetworkMember for NengoObjects and NengoObjectContainer for Network.

Other changes:

- Added with_metaclass function to utils.compat, as Python 2 and 3 have different syntax for this.
- Added Network.add which encapsulates some of the logic that used to be NengoObject.__init__
- Made NengoObject.__str__ a bit safer and easier to read

Mostly I wanted to put this out there to see if people agree that this makes Network creation easier / more Pythonic. Some ideas I had along these lines that I'll implement before a rigorous review:

1. We could make all methods inside a `Network` automatically use `with self`. Right now, only `__init__` does this, but since we're using metaclasses, we can do this for all methods automatically if we so choose.
2. With these changes, I think getting rid of `add_to_network` and instead putting all the logic in `Network.add` makes more sense. Right now, that function is the only thing (other than the metaclass) that makes Ensemble etc. have to know about their network.