Skip to content

Class deprecation machinery and mixins #18690

@anntzer

Description

@anntzer

Bug report

In

@cbook.deprecated("3.4")
class Mixin:
    pass

class Base:
    def __init__(self, x): self.x = x

class Mixed(Mixin, Base):
    pass

Mixed(x=1)

the last line raises a rather puzzling

TypeError: object.__init__() takes exactly one argument (the instance to initialize)

because the deprecation machinery grabs object.__init__ to install the deprecation emitter on Mixin. (This is not a theoretical case, see e.g. #18675.)

There's a few possible solutions:

  • "it's too rare, let's not bother"
  • forbid deprecation of classes where __init__ is not defined (which I think is the main failing case)
  • make cbook.deprecated actually create another class that inherits from Mixin and has its own __init__ (which gets wrapped in cbook.deprecated() and just calls super().__init__), instead of monkey-patching Mixin's original __init__.

Matplotlib version

  • Operating system: n/a
  • Matplotlib version: HEAD
  • Matplotlib backend (print(matplotlib.get_backend())): n/a
  • Python version: n/a
  • Jupyter version (if applicable):
  • Other libraries:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy