Skip to content

Handling "default" methods in class hierarchies #5669

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

Closed
rpgoldman opened this issue Sep 25, 2018 · 3 comments
Closed

Handling "default" methods in class hierarchies #5669

rpgoldman opened this issue Sep 25, 2018 · 3 comments

Comments

@rpgoldman
Copy link

rpgoldman commented Sep 25, 2018

feature request

See the directory test-data/default-methods/ in my branch: https://github.com/rpgoldman/mypy/tree/default-method-example

cd mypy/test-data/default-methods/code
mypy example.py

Complains that the SubClass method signature contradicts the one at SuperClass (which has a vacuous parameter list):

../stubs/example_classes.pyi:13: error: Signature of "example_method" incompatible with supertype "SuperClass"

Ideally, mypy should recognize that a method definition whose signature is:

(self, *args: Any, **kwargs: Any)

does not constrain any subclass's implementations of that method.

  • What are the versions of mypy and Python you are using?
mypy 0.640+dev-b923c587a3eaa6cb55d9908be5344b2d9a574b33

Python 3.6

  • What are the mypy flags you are using? (For example --strict-optional)

none

@rpgoldman
Copy link
Author

P.S. in the PyMC3 code base I see these vacuously-parameterized methods used for delegation and for raising exceptions where a method is not implemented, but should be. I think there is probably a better mechanism for the latter, but I'm not as sure about the former.

@ilevkivskyi
Copy link
Member

As a random suggestion, we can maybe make it a strictness flag, like in #5670 instead of adding a special decorator or similar.

@hauntsaninja
Copy link
Collaborator

Modern mypy is more unsound in its handling of *args: Any, **kwargs: Any

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants