Created
June 29, 2014 18:04
-
-
Save olavmrk/ff01726bd04f86984b91 to your computer and use it in GitHub Desktop.
Testing storing references to @staticmethod in class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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