Constructors assigned to roles by Python Flask Web-User Model

Flask Web Development in Section 9.2, the role assigned to the user is done in the constructor of the User model

class UserMixin(object):
    """
    This provides default implementations for the methods that Flask-Login
    expects user objects to have.
    """
    @property
    def is_active(self):
        return True

    @property
    def is_authenticated(self):
        return True

    @property
    def is_anonymous(self):
        return False

    def get_id(self):
        try:
            return unicode(self.id)
        except AttributeError:
            raise NotImplementedError("No `id` attribute - override `get_id`")

    def __eq__(self, other):
        """
        Checks the equality of two `UserMixin` objects using `get_id`.
        """
        if isinstance(other, UserMixin):
            return self.get_id() == other.get_id()
        return NotImplemented

    def __ne__(self, other):
        """
        Checks the inequality of two `UserMixin` objects using `get_id`.
        """
        equal = self.__eq__(other)
        if equal is NotImplemented:
            return NotImplemented
        return not equal

    if sys.version_info[0] != 2:  -sharp pragma: no cover
        -sharp Python 3 implicitly set __hash__ to None if we override __eq__
        -sharp We set it back to its default implementation
        __hash__ = object.__hash__

but look at the source code of the UserMixin class and get confused. The constructor _ _ init__ is not defined in the UserMixin class. So how does the instance call the constructor of the parent class UserMixin and inherit the properties of the parent class? Welcome all the experts to answer! Thanks.

May.05,2022

MRO is searched by breadth-first traversal. When there is no _ _ init__ in the UserMixin class, the next search item goes to the db.Model class. I guess there should be a custom _ _ init___ method

in this class.
Menu