#๐ non-None assertion operator?
22 messages ยท Page 1 of 1 (latest)
@kindred pier
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
assert x is not None?
(That's a statement tho)
I know I can do a cast, but its so messy
you can probably write a function for it
You could always make your own typegaurd function if you really need to do a expression
from typing import cast
doSomething(cast(MyType, my_non_null_type))
I was thinking put the assert in a function
Idk if that would work with a checker though
we've already verified the type isn't None elsewhere
its just the type checker that fails to reaize it
the assert function would basically be a cast
But you would not specify the type you want it to be which is easier
hmmm
But to be honest I would always just:
assert i_am_not_null is not None # we checked that it was not none above
do_something(i_am_not_null)
And if i_am_not_null is a function call or something, just assign it to a variable first
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.