Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Erroneous number of arguments is reported in a constructor call with multiple inheritance #5299

Closed
gh-andre opened this issue Jun 14, 2023 · 3 comments
Labels
addressed in next version Issue is fixed and will appear in next published version bug Something isn't working

Comments

@gh-andre
Copy link

Describe the bug

When multiple inheritance is used, a call of one of the __init__ methods in __mro__ order is reported as if it expects zero arguments, when the referenced constructor expects arguments.

To Reproduce
This is an example with constructors with different arguments.

class XB:
    def __init__(self) -> None:
        # this would call Y.__init__ in Z.__mro__ order, but there's no `name`/`num` to pass in
        #super().__init__()
        pass

class X(XB):
    def __init__(self, name: str) -> None:
        super().__init__()
        print(f"Use {name} for side effects")

class Y:
    def __init__(self, name: str, num: int):
        self.name = name
        self.num = num

# Z.__mro__ = (Z, X, XB, Y, object)
class Z(X, Y):
    def __init__(self, name: str, num: int) -> None:
        super().__init__(name)
        # call Y.__init__
        super(XB, self).__init__(name, num) # <-  error: Expected 0 positional arguments (reportGeneralTypeIssues)
        
z: Z = Z("abc", 123)

Having constructors arranged to have same arguments, which isn't always doable for obvious reasons, reports the same error, just in the different spot.

class XB:
    def __init__(self, name: str, num: int) -> None:
        # calls Y.__init__(name, num)
        super().__init__(name, num) # <- error: Expected 0 positional arguments (reportGeneralTypeIssues)

class X(XB):
    def __init__(self, name: str, num: int) -> None:
        super().__init__(name, num)

class Y:
    def __init__(self, name: str, num: int) -> None:
        super().__init__()
        self.name = name
        self.num = num

# Z.__mro__ = (Z, X, XB, Y, object)
class Z(X, Y):
    def __init__(self, name: str, num: int) -> None:
        super().__init__(name, num)
        
z: Z = Z("abc", 123)

Expected behavior

In both cases the Y.__init__ call requires arguments and should not be reported as an error.

Additional context

Observed in the latest Visual Studio and in pyright v1.1.304 on Windows, with Python 3.10.

@gh-andre gh-andre added the bug Something isn't working label Jun 14, 2023
erictraut pushed a commit that referenced this issue Jun 14, 2023
…` call. There were situations where the incorrect MRO class was used. This addresses #5299.
erictraut pushed a commit that referenced this issue Jun 15, 2023
…` call. There were situations where the incorrect MRO class was used. This addresses #5299.
erictraut pushed a commit that referenced this issue Jun 15, 2023
…` call. There were situations where the incorrect MRO class was used. This addresses #5299.
erictraut added a commit that referenced this issue Jun 15, 2023
…` call. There were situations where the incorrect MRO class was used. This addresses #5299. (#5304)

Co-authored-by: Eric Traut <[email protected]>
@erictraut
Copy link
Collaborator

Thanks for the bug report along with the great repro and code sample. This will be fixed in the next release.

@erictraut erictraut added the addressed in next version Issue is fixed and will appear in next published version label Jun 15, 2023
@erictraut
Copy link
Collaborator

This is included in pyright 1.1.315, which I just published. It will also be included in this week's insiders release of pylance.

@gh-andre
Copy link
Author

@erictraut Thank you. Much appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addressed in next version Issue is fixed and will appear in next published version bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants