Skip to content

TypeError when calling isinstance on a TrameApp decorated object #594

Closed
@MattTheCuber

Description

@MattTheCuber

Describe the bug

Using isinstance on a @TrameApp() decorated class throws a TypeError.

TypeError: isinstance() arg 2 must be a type, a tuple of types, or a union

To Reproduce

Steps to reproduce the behavior:

  1. Run the following code.

Code

from trame.decorators import TrameApp


@TrameApp()
class TestApp:
    server = None


t = TestApp()
print(isinstance(t, TestApp))

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. The TypeError 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:

  • Windows
  • MacOS
  • Linux
  • Android
  • iOS

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions