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

Plugins and overloads don't interact well #7367

Open
ilevkivskyi opened this issue Aug 19, 2019 · 2 comments
Open

Plugins and overloads don't interact well #7367

ilevkivskyi opened this issue Aug 19, 2019 · 2 comments
Labels
bug mypy got something wrong needs discussion priority-0-high topic-overloads topic-plugins The plugin API and ideas for new plugins

Comments

@ilevkivskyi
Copy link
Member

While working on our own plugin for self-checking proper types and isinstance() I have tried to use get_function_hook() to emit some additional errors for overloaded functions. However this didn't work for three reasons:

  • The hook is called for every item in the overload, not for the overload as a whole.
  • The overload logic relies on empty Messages as a sign of successful match
  • The errors emitted during overload selection are discarded afterwards, thus discarding the plugin generated errors

This issue can be fixed in three ways:

  • Calling the hook on the overload as a whole after selecting the overload variant and type checking it (this however will be a breaking API change)
  • Use newly added error codes to only abandon a variant if the error is due to bad argument type (this is however still bad because check_call() may have an accept() call possibly triggering almost arbitrary error including a nested function call with bad argument type).
  • Use a boolean attribute somewhere that will be set by check_argument_types() and will be reset after return from every accept().

I am leaning towards the last option, since it is most principled IMO.

cc @Michael0x2a

@tapaswenipathak
Copy link
Contributor

Hi @ilevkivskyi: I would like closing the issue. Can I PR?

@ilevkivskyi
Copy link
Member Author

Sure, you can try, but note that this may not be the best issue for a new contributor. If you would like to try few simpler issues first we have a special label https://github.com/python/mypy/issues?q=is%3Aopen+is%3Aissue+label%3Agood-first-issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong needs discussion priority-0-high topic-overloads topic-plugins The plugin API and ideas for new plugins
Projects
None yet
Development

No branches or pull requests

2 participants