Skip to content

@deprecated breaking __init__ inheritance when used with mixins/multiple inheritance #251

@recrsn

Description

@recrsn

When a class without __init__ (mixin) is used in multiple inheritance and marked as deprecated, inheritance of __init__ doesn't work.

Example:

from typing_extensions import deprecated


class Service:
    def __init__(self, foo: str, bar: str) -> None:
        print("Service.__init__")
        self.foo = foo
        self.bar = bar

    def echo(self) -> None:
        print("Service.echo", self.foo, self.bar)


class Base:
    def message(self) -> None:
        print("Base.message")


class Child(Base):
    def message(self) -> None:
        print("Child.message")
        super().message()


@deprecated("Use Child instead")	# removing this will work normally
class FooBarPrinter(Child):
    def message(self) -> None:
        print("FooBarPrinter.message")
        super().message()


class Spam(Service, FooBarPrinter):
    def do_work(self):
        self.echo()
        self.message()


if __name__ == "__main__":
    Spam("foo", "bar").do_work()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions