-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
assertIsNotNone(foo) in tests is not treated the same as assert foo is not None
#5088
Comments
Is @overload
def assertisNotNone(obj: None) -> NoReturn: ...
@overload
def assertIsNotNone(obj: Any) -> None: ... Haven't tested it though. |
@JelleZijlstra that's #4063. It is not implemented. |
It's part of the standard unittest library: https://docs.python.org/2/library/unittest.html#unittest.TestCase.debug |
I think this can be closed in favor of #4063 then. |
Is that something that should be added to the typeshed description of unittest then? I checked https://github.com/python/typeshed/blob/master/stdlib/unittest/case.pyi#L120 which reads this:
I have seen the forward to #4063. However, that issue is open for 5 years with no result. And currently I prefer to have this issue solved. I just do not want to double-check everything with both an assert statement and a unittest check. I also do not want to refactor all unittests of a project just because of a missing functionality of mypy. I hope that makes it understandable why it might be more reasonable to pick up this track. Thank you! |
Using assert because mypy does not yet support type guards from unittest See python/mypy#5088
Using assert because mypy does not yet support type guards from unittest See python/mypy#5088
mypy doesn't yet understand that `assertIsNotNone` validates the non-None nature of the variable. Related issues: - python/mypy#5088 - python/mypy#4063 - python/typing#930
That PR arrived while our CI was broken and I manually verified that the tests passed but didn't run the linters. These changes are running in to python/mypy#5088
As part of Zulip's strict-optional effort, I had to convert a test that was using
assertIsNotNone(foo)
to useassert foo is not None
in order to get mypy to pass. I think mypy should treat those two the same.The text was updated successfully, but these errors were encountered: