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

Specilizing Union method parameters on subclasses #6411

Closed
athoscouto opened this issue Feb 15, 2019 · 3 comments
Closed

Specilizing Union method parameters on subclasses #6411

athoscouto opened this issue Feb 15, 2019 · 3 comments

Comments

@athoscouto
Copy link

Feature Request
Extend feature added in #424 to allow subclasses to also specialize method parameters that contain Union type.

Code example

class A():
    def x(self, x: Union[Dict, List]):
        pass


class B(A):
    def x(self, x: Dict):
        pass

mypy output
error: Argument 1 of "x" incompatible with supertype "A"

Expected output
Nothing :)

mypy/python version
mypy 0.641
Python 3.6.7

@intgr
Copy link
Contributor

intgr commented Feb 20, 2020

I think this issue is mistaken. The contract of A states "all A classes contain method x that accepts argument Union[Dict, List]".

The method B.x violates that contract because it does not accept List.

@intgr
Copy link
Contributor

intgr commented Feb 20, 2020

This is basically duplicate of #1237.

@JukkaL
Copy link
Collaborator

JukkaL commented Feb 20, 2020

Yeah, the method in B violates Liskov substitution principle (https://en.wikipedia.org/wiki/Liskov_substitution_principle).

@JukkaL JukkaL closed this as completed Feb 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants