Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

post_init and other hooks are coded as instance methods but aren't actually instance methods #44

Open
pcraciunoiu opened this issue Nov 15, 2012 · 0 comments
Milestone

Comments

@pcraciunoiu
Copy link
Contributor

This leads to a bit of weirdness where you have to call self.post_init() and pass self as the first argument.

Per Andy's comments, here is how it currently works:

>>> class a(object):
...   pass
...⋅
>>> def foo(self):
...   self.a = 5
...⋅
>>> b = a()
>>> b.hello = foo
>>> b.hello()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: foo() takes exactly 1 argument (0 given)
>>> b.hello(b)
>>> b.a
5

And here is how it could work:

>>> class a(object):
...   pass
...⋅
>>> def foo(self):
...   self.a = 5
...⋅
>>> b = a()
>>> import types
>>> b.hello = types.MethodType(foo, b)
>>> b.hello()
>>> b.a
5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant