Open MattTheCuber opened 1 week ago
That is a good issue but I'm not sure how to solve that... maybe by doing the following
from trame.decorators import TrameApp
class TestApp:
server = None
t = TrameApp()(TestApp)()
print(isinstance(t, TestApp))
That is a solution, although fairly hard to follow in practice
yes, I agree and I'm not sure how to solve that.
I asked Chat and it suggested creating a wrapper class with the decorator.
class TrameApp:
def __call__(self, klass):
class WrappedClass(klass):
...
return WrappedClass
It could work, but then it could introduce other problems with type checking since type(t)
would return WrappedClass
instead of TestApp
.
We might be able to re-design the class a little bit to support this. I might look into it later this week.
I just found another issue that the function wrapper may be causing. Not quite sure why this is occuring though:
from trame.decorators import TrameApp
@TrameApp()
class TestApp:
server = None
@TrameApp()
class TestApp2(TestApp):
server = None
t = TestApp()
t2 = TestApp2()
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[2], line 10
4 @TrameApp()
5 class TestApp:
6 server = None
9 @TrameApp()
---> 10 class TestApp2(TestApp):
11 server = None
14 t = TestApp()
TypeError: function() argument 'code' must be code, not str
If this a separate problem, I can make a new issue. I will look into it more tomorrow probably.
I think this is related because the decorated TestApp is actually a function and not a class which prevent you from inheriting it.
Describe the bug
Using
isinstance
on a@TrameApp()
decorated class throws aTypeError
.To Reproduce
Steps to reproduce the behavior:
Code
Expected behavior
I would assume
isinstance
would work. This is not a critical problem though as we have other workarounds.The problem is that the
@TrameApp()
decorator returns a function that instantiates the class instead of returning a class itself. TheTypeError
is thrown because we are checking if a object is an instance of a function, which is not possible to check.Maybe
isinstance
would never be a good way to handle this, either way it would be very useful to have a good way of checking the type of our app's instances.Platform:
OS: