Skip to content

Is there an equivalent of isinstance() of python #1982

@wonderyl

Description

@wonderyl

General Question

I'm trying to write a function that behaves differently based on the type of the schemas. E.g.

schema Parent:
  a: int

schema Child(Parent):
  b: int

schema GrandChild(Child):
  b = 2

schema foo[s: any]:
  output: int

  if isinstance(s, Child):
    output = s.b
  else:
    output = s.a

bar = foo(GrandChild{})

The build in typeof() function doesn't work because it doesn't expose inheritance chain.

Any suggested would be appreciated.

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