-
Notifications
You must be signed in to change notification settings - Fork 127
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
Decorators on static and instance method order #39
Comments
You don't seem to understand how decorators work. There is no issue with the way decorators work. You are calling isTestable on the target prototype, i.e. the prototype of the decorated class. Please close as invalid/personal learning process. |
@silkentrance Well, I fixed the code example, now it is called on instance. Is it really changing something? |
@just-boris yes, this is correct, now you just have to fix your logic. Hadlner should be called when testable, right? So, it actually is testable as it is being called and will throw the exception. |
@silkentrance well, thank you that you pointed that my example is not clear. I am going to use the conjunction of two decorators to set up debugging for my classes. First, mark some methods as |
@just-boris again, your logic is off. class decorators get applied after that the class was defined. see
where debugEnabled gets called right before the defined class will be returned. And before you go and cry out about this being wrong. See for example the way Python decorators work. In fact, the Python interpreter will first call any method / property decorators and will at the very last call upon the class decorators. And this is good, since it has enable the Python community to come up with great frameworks based on that approach, see for example Zope.Interface and what not. So you need to invert your logic here, marking these methods as in debug only, for example with the symbol and then, when it comes to your class decorator, you will have to eliminate those which should be available during debug only. But then be sure to also decorate your first class, otherwise it will not work for that, too. And, perhaps, you should consider trying a different approach?
The above is a well known and commonly accepted pattern. Alternatively you could rewrite your debugOnly decorator like this
or something like that. |
I din't found in this document description of decoration applying order. But I think that is good to have it standardized.
So, what's the order of decorations, who goes first: class, static or prototype decorators?
Also, babel now applies prototype decorators before static, which causes issues, but that is technically correct, because the spec has nothing about it. See a Babel REPL with unexpected result.
The text was updated successfully, but these errors were encountered: