Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
recrsn opened this issue Jun 22, 2023 · 2 comments · Fixed by #294
Closed

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

recrsn opened this issue Jun 22, 2023 · 2 comments · Fixed by #294

Comments

@recrsn
Copy link

recrsn commented Jun 22, 2023

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()
@ljluestc

This comment was marked as off-topic.

@JelleZijlstra
Copy link
Member

Thanks for the report (and sorry for the slow response).

@deprecated's patching of classes is a bit fragile and in some cases, the best solution may be to pass category=None and disable the runtime DeprecationWarning. However, for this case I found a solution; PR incoming.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants