Last active
June 22, 2016 10:50
-
-
Save kmmbvnr/53fe9b92a4d7c3703cbb to your computer and use it in GitHub Desktop.
Little python quiz
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
| """ | |
| Implement @secret_decorator allows to bypass decorator on base class method | |
| """ | |
| class Base(object): | |
| @secret_decorator | |
| def method(self): | |
| print('base') | |
| class Child(Base): | |
| @secret_decorator | |
| def method(self): | |
| print('child') | |
| # bypass super/secret_decorator and directly call method impl | |
| super(Child, self).method.original() | |
| """ | |
| >>> base, child = Base(), Child() | |
| >>> base.method() | |
| decorated | |
| base | |
| >>> child.method() | |
| decorated | |
| child | |
| base | |
| """ |
sureshvv
commented
Nov 29, 2014
Author
btw @sureshvv the solution contains a bug. In case of child.method() the self inside of base.method is not Child instance, but Desc instance
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment