Skip to content

Mixins with conflicting signatures #2125

Closed
@rowillia

Description

@rowillia

I'm finding it's quite common to have Python Libraries using mixins with signatures that mypy considers to be conflicting because one takes a different set of kwargs than the other. For example - https://github.com/pallets/itsdangerous/blob/master/itsdangerous.py#L881-L886 (which is simplified below).

class A(object):
    def load(self, payload):
        pass
class B(object):
    def load(self, payload, return_header=False):
        pass
    def dump(self, obj):
        pass
class C(A, B):
    pass

In this case, mypy will complain that A and B have conflicting signatures for load. In practice, Python will always dispatch load calls to A so C's signature for load should be load(self, payload). It would be incorrect to pass return_header to C().load.

What are your thoughts on having mypy reflect what Python will do at runtime here and just take the definition of A's load instead of throwing an error? The only way around this currently is to add **kwargs to As signature which is less safe.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions