[Python] Handle shadowed attribute in multiple inheritance

Discussão em 'Python' iniciado por Stack, Junho 19, 2025.

  1. Stack

    Stack Membro Participativo

    What is the best way to handle attribute shadowing from multiple inheritance?

    Intended behavior is to end up with a Field.

    from pydantic import BaseModel

    class Parent(object):
    value: int = 1

    class Shadow(BaseModel, Parent):
    value: int = 2

    Shadow()


    Options I have considered:

    1. Should I silence the warning? If so, how?
    2. Is there a model or field configuration option?
    3. Don't do multiple inheritance that shadows.

    Continue reading...

Compartilhe esta Página