I'm positive this has been answered, but I'm not able to find the response, probably because I'm not searching the right terms.
I have this code:
object_session(self).scalars(
object_session(self) can returns Session | None, but in this use case, I know it will return a Session. How can I make the checker (ruff) happy with the line? I know I could do something like
session = object_session(self)
if not session:
raise Exception()
session.scalars
But that's wordy, specially as if there's no session, there would have been a problem upstream anyway.