-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Add no-overload-impl error code #11944
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
Conversation
@hauntsaninja following up on your message on gitter, I've opened a PR that adds the relevant error code. Please take a look when you have a chance, thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to update tests in https://github.com/python/mypy/blob/master/test-data/unit/check-errorcodes.test ?
Added, thanks! I missed that the test cases were mostly defined under test-data |
Diff from mypy_primer, showing the effect of this PR on open source code: steam.py (https://github.com/Gobot1234/steam.py)
- steam/ext/commands/bot.py:671: error: An overloaded function outside a stub file must have an implementation [misc]
+ steam/ext/commands/bot.py:671: error: An overloaded function outside a stub file must have an implementation [no-overload-impl]
pytest (https://github.com/pytest-dev/pytest)
+ src/_pytest/mark/structures.py:405: error: An overloaded function outside a stub file must have an implementation [no-overload-impl]
+ src/_pytest/mark/structures.py:423: error: An overloaded function outside a stub file must have an implementation [no-overload-impl]
|
@bphillips-exos can you please check why this new entry in mypy_primer is shown?
This might be a newly added code, but it is better to double check 🙂 |
Here is the relevant snippet from the pytest source code. Pytest is overriding the annotations for some decorator definitions with overloads. The ignore[misc] decorator is required because this is a python file, not pyi. If this PR is merged, pytest would simply need to modify the ignore comment to be # Typing for builtin pytest marks. This is cheating; it gives builtin marks
# special privilege, and breaks modularity. But practicality beats purity...
if TYPE_CHECKING:
from _pytest.fixtures import _Scope
class _SkipMarkDecorator(MarkDecorator):
@overload # type: ignore[override,misc] (L405)
def __call__(self, arg: _Markable) -> _Markable:
raise NotImplementedError()
@overload # noqa: F811
def __call__(self, reason: str = ...) -> "MarkDecorator": # noqa: F811
raise NotImplementedError() |
mypy_primer runs your branch of mypy on multiple open-source projects. Looks like the reason for the new issue is exact |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! It seems to me like it might make sense for this error code to be generalised to something like "overload-def". It could cover a couple other lints that mypy has about overload definitions, for instance "Single overload definition, multiple required" and "@Final should be applied only to overload implementation". Thoughts?
Hi hauntsaninja, I actually don't like the idea of generalizing error codes. In my opinion, much of the value of error codes comes from being able to be very specific about which errors to ignore. I find pylint does this very well and I can turn off specific checks when they don't make sense for a particular project. For the use case I am trying to address with this PR, I have a codebase which supports dynamic dispatch based on overloaded function signatures. I would like to disable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good, thank you again :-)
Description
Adds a new
no-overload-impl
error code that is raised when overloaded functions outside of stub files are not followed by an implementation.Test Plan
I validated the doc changes and all tests are passing locally. I did not find anywhere in the tests that the error code of specific failures is checked, but please let me know if I missed something.