1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Enforce __init__ method's arguments are superset of base class

Discussão em 'Python' iniciado por Stack, Novembro 25, 2025.

  1. Stack

    Stack Membro Participativo

    We use pyre for linting and have been updating some old polymorphic code to be typed. The __init__ method has quite a few arguments and was using **kwargs to pass them through the various layers with each layer adding a few more. To make them strongly typed we ended up just replicating the arguments everywhere. But if we add a new arg to the base class we have to remember to put it everywhere else.

    So my initial thought was that maybe there was a way to create a type assertion between the classes that the method args are supersets of their base classes.

    I'm my research I was also seeing some discussions around using typed dicts to define the arguments for each layer and merge them. But my python-foo is not strong and the examples seemed incomplete so I didn't even attempt that option.

    How can I enforce the init arguments are a superset of the base class?

    Continue reading...

Compartilhe esta Página