You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Consider allowing assertIsNotNone() to constitute a None check #2007
Because unittest is part of the standard library, it would be convenient if calling assertIsNotNone (and assertIsNone) would be constitute a None check from the type checker's perspective.
Additional context
It might be too magical to apply special treatment to these methods. Perhaps there should (eventually) be a generalized typing facility that assertIsNone/assertIsNotNone could adopt, a la TypeGuard.
Reacted by Dave Tapley, Jan Holthuis, Marvin Kastner, Arusekk, Michael Reeves, Claudio Catterina, Gonzalo Lescano, Lennart, penenkel, Yossi Vainshtein and 6 more
We generally don't hard code any knowledge of specific functions or methods. It's just not a scalable approach to type checking. Type information should come from the type stubs, even for stdlib methods.
In my code, I've worked around this by switching from assertIsNotNone to assert is not None. Another option is to disable the reportOptionalMemberAccess diagnostic check in your test files using a # pyright: reportOptionalMemberAccess=false comment at the top of the file.
We have made exceptions to the above principle in very rare cases but only after we received significant signal from pyright/pylance users. I'm going to close this issue for now, but we can consider reopening it in the future if it receives a bunch of upvotes or additional requests.
Well, this issue arises at different corners of GitHub, see also python/typeshed#8583 and the issues mentioned therein. People are still in need of this feature :)
Reacted by Dave Tapley, Evgeny Filatov, nikki and Meiyer
Activity
erictraut commentedon Jun 18, 2021
We generally don't hard code any knowledge of specific functions or methods. It's just not a scalable approach to type checking. Type information should come from the type stubs, even for stdlib methods.
In my code, I've worked around this by switching from
assertIsNotNonetoassert is not None. Another option is to disable thereportOptionalMemberAccessdiagnostic check in your test files using a# pyright: reportOptionalMemberAccess=falsecomment at the top of the file.We have made exceptions to the above principle in very rare cases but only after we received significant signal from pyright/pylance users. I'm going to close this issue for now, but we can consider reopening it in the future if it receives a bunch of upvotes or additional requests.
1kastner commentedon Aug 23, 2022
Well, this issue arises at different corners of GitHub, see also python/typeshed#8583 and the issues mentioned therein. People are still in need of this feature :)