```python
def foo():
    class Bar(object):
        def __new__(cls):
            print "class new..."
            return object.__new__(cls)

        def __init__(self):
            print "class init"

        def bar(self):
            print "method bar"

    b = Bar()
    b.bar()
```
the class is indeed created on each function invocation. I think it'd be better if the class is defined under the parent class scope instead.