Skip to content

Instantly share code, notes, and snippets.

@olavmrk
Created June 29, 2014 18:04
Show Gist options
  • Save olavmrk/ff01726bd04f86984b91 to your computer and use it in GitHub Desktop.
Save olavmrk/ff01726bd04f86984b91 to your computer and use it in GitHub Desktop.
Testing storing references to @staticmethod in class
#!/usr/bin/env python
class Hello(object):
@staticmethod
def _hello_impl_1():
print 'Hello world!'
_hello_impl = None
@staticmethod
def hello():
if Hello._hello_impl == None:
Hello._hello_impl = Hello._hello_impl_1
Hello._hello_impl()
Hello.hello()
# Above call fails with:
#Traceback (most recent call last):
# File "./statictest.py", line 12, in <module>
# Hello.hello()
# File "./statictest.py", line 11, in hello
# Hello._hello_impl()
#TypeError: unbound method _hello_impl_1() must be called with Hello instance as first argument (got nothing instead)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment