False Warning: "Unexpected argument" when using python multiple inheritance. Follow
Hello. My Pycharm version is 2021.1.3
An "Unexpected argument" warning occurs during Python multiple inheritance usage.
Is this Pycharm error?
class TestParentClass(object):
def __init__(self, *args, **kwargs):
pass
def ReturnClass(*args, **kwargs):
return TestParentClass()
testParentClass: TestParentClass = ReturnClass()
class TestMixin(object):
pass
class TestClass(TestParentClass, TestMixin): # class TestClass(TestMixin, TestParentClass): both
pass
b = TestClass(b=10) # There is no warning.
class TestParentClass(object):
def __init__(self, *args, **kwargs):
pass
def ReturnClass(*args, **kwargs) -> TestParentClass:
return TestParentClass()
testParentClass: TestParentClass = ReturnClass()
class TestMixin(object):
pass
class TestClass(testParentClass, TestMixin): # class TestClass(TestMixin, testParentClass) both
pass
b = TestClass(b=10) # Unexpected argument
class TestParentClass(object):
def __init__(self, *args, **kwargs):
pass
def ReturnClass(*args, **kwargs) -> TestParentClass:
return TestParentClass()
testParentClass: TestParentClass = ReturnClass()
class TestMixin(object):
def __init__(self, *args, **kwargs):
pass
pass
class TestClass(TestMixin, testParentClass): # class TestClass(testParentClass, TestMixin) both
pass
b = TestClass(b=10) # There is no warning
I understand that using Python Mixin does not define __init__. However, to remove this warning, I need to define __init__.
Is this a bug? Or does it work normally?
This issue was observed when defining a table using "from sqlalchemy.ext.declarative import descriptive_base" and mixin in SQLAlchemy.
Thank you.
Please sign in to leave a comment.
I'm having a similar issue as I work through "The Flask Mega-Tutorial".
In my case, I have a model that uses a mixin:
And, when I try to instantiate this object with the following code I receive "Unexpected Argument" error on the `user = User(...` line despite the code executing perfectly well:
The code above is nearly 100% pure copy of the tutorial code.
Hi, here are couple of possibly related issues:
https://youtrack.jetbrains.com/issue/PY-7712/Support-for-mixin-classes-in-code-inspection
https://youtrack.jetbrains.com/issue/PY-43006/PyCharm-is-unable-to-show-code-completion-for-mixin-methods
If you think this is your case, please add your vote.