[Python] I can't figure out why `isinstance()` returns `True` for these subclasses

Discussão em 'Python' iniciado por Stack, Fevereiro 6, 2025.

  1. Stack

    Stack Membro Participativo

    I'm using the Python package ariadne, v0.23.0.

    I wrote a utility to scan my code for instances of ariadne.types.SchemaBindable, but it's also unintentionally picking up the SchemaBindable subclasses that I've imported:

    ariadne.input.InputType( SchemaBindable )
    ariadne.objects.ObjectType( SchemaBindable )
    ariadne.scalars.ScalarType( SchemaBindable )
    ariadne.unions.UnionType( SchemaBindable )


    I ran a test in a Python shell, and sure enough, isinstance() is returning True when comparing those classes to SchemaBindable:

    isinstance( ObjectType, SchemaBindable ) -> True
    ...etc...


    SchemaBindable even appears to be an instance of itself:

    isinstance( SchemaBindable, SchemaBindable ) -> True


    Meanwhile, issubclass() continues to also return True:

    issubclass( ObjectType, SchemaBindable ) -> True


    Make it make sense.

    Continue reading...

Compartilhe esta Página