Skip to content

A utility to confirm "or None" types are not None #1997

Closed Answered by sobolevn
hunterhogan asked this question in Q&A
Discussion options

You must be logged in to vote
def raise_if_none[T](obj: T | None) -> T:
    if obj is None:
        raise TypeError('message')
    return obj

I think that this 3-line-function is easy enough to be just written, when you need it 🤔

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by hunterhogan
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants