[Python] only change type annotation of method in subclass

Discussão em 'Python' iniciado por Stack, Maio 15, 2025.

  1. Stack

    Stack Membro Participativo

    Is it possible to change/"override" the return type of a method in a subclass without overriding/altering the method (implementation) itself? Something like:

    class Foo:
    def gimme_thing() -> Thing:
    return self.factory.create()

    class Bar(Foo):
    def gimme_thing() -> BarThing: ... # <--- for Bar the factory will a return another type, how to spell this?

    Continue reading...

Compartilhe esta Página