-
Notifications
You must be signed in to change notification settings - Fork 53
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
Circumventing Name "_" already defined
mypy error
#268
Comments
Ugh, that's unfortunate. It's discussed in detail at python/mypy#2904 in the context of |
Cool, didn't think about searching mypy issue tracker but yeah that's precisely the same problem. So even more incentive and use cases for the mypy plugin it seems. |
As a temporary solution I've found out that configuring disable_error_code = ["no-redef"] works well. Unfortunately it seems that it can not be configured on a per module basis, so it will disable mypy my-project/
mypy --disable-error-code=no-redef tests/ Alternatively, if using |
This was recently fixed in mypy master: A quick loosely related question (happy to move it to a separate issue): Do you have plans for allowing strict type-checking of tests using the default argument syntax? The issue I see here is that the parameter should be annotated with the type of the value injected into the test, but the default argument has the type of the fixture that provides the value. It seems analogous to how dataclasses.field works, and would probably require a mypy plugin as well? |
As @cjolowicz mentioned this was fixed in mypy and is now released in mypy 0.920 so there is no longer an issue. I'm closing the issue. @cjolowicz I moved your question to #310 so it can be discussed in an open issue. |
Mypy really hates the pattern of naming every test like
def _():
and errors on every Ward test with the messageName "_" already defined on line 79 [no-redef]
.Type checking tests still often makes sense, so we should come up with a good way to circumvent the error and document that. Best would perhaps be if mypy had a configuration option to disable this specific error only, and only disable it in a test directory. That doesn't seem to be possible though.
Adding a
# type: ignore[no-redef]
after each@test
decorator line works but is a bit laborious. Maybe make an auto-formatter (supporting pre-commit framework) that adds these ignore comments? Or even better, maybe there's a way to make a mypy plugin that tricks mypy into thinking these comments are in place, even if they really aren't (less clutter in the codebase).The text was updated successfully, but these errors were encountered: