1

I'm trying to implement a custom mixin in Python 3.6. Child classes would inherit its methods as well as base class.

db = flask_sqlalchemy.SQLAlchemy()


class CustomMixin(object):
    # {... __init__ is not being explicitly called, instance and class methods go here ...}


class UserModel(CustomMixin, db.Model)
    # {... class variables, own and inherited methods go here ...}

However, although my solution works, it gives a weak warning in PyCharm Community 2019.2:

user = UserModel(class_var_1=value_1, class_var_2=value_2) # Here the warning appears

Full warning text is the following:

Unexpected argument(s)
Possible callees:
object(self: object)
object.__new__(cls: object)

What are possible reasons of this warning? Could it be an issue related to inheritance chain?

ntonk
  • 95
  • 8
  • 2
    You have different signatures for `__init__` in your base classes. See [this question](https://stackoverflow.com/questions/26927571/multiple-inheritance-in-python3-with-different-signatures) for a similar case. In short, adding an `__init__` method to your mixin (i.e. `def __init__(self, *args, **kwargs):`) should fix this. – Selcuk Jan 06 '20 at 03:41
  • @Selcuk Indeed that does fix it but there is no reason we should need to define an __init__ on a mixin since python doesn't automatically call __init__ methods of all objects in the MRO. Don't write code to satisfy buggy IDE inspections. See Jetbrains ticket here: https://youtrack.jetbrains.com/issue/PY-49864 – medley56 Jan 29 '22 at 14:03

0 Answers0